Skip to content

Ben Tsao - #442

Open
cbtsao47 wants to merge 16 commits into
bloominstituteoftechnology:masterfrom
cbtsao47:master
Open

Ben Tsao#442
cbtsao47 wants to merge 16 commits into
bloominstituteoftechnology:masterfrom
cbtsao47:master

Conversation

@cbtsao47

Copy link
Copy Markdown

No description provided.

@ashwins93 ashwins93 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Good git commits. Keep working on the code challenges to understand more about JavaScript.

// The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName.
let fullName = [];
runners.forEach(function(runner) {
fullName.push(`${runner.first_name} ${runner.last_name}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literals used aptly.

// The boss wants a list of the runners with their last names in alphabetical order
let sortedNames = [];
let allNames = runners.map(runner => runner.last_name);
sortedNames = allNames.sort();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort changes the array in-place so in this case sortedNames is redundant

sortedNames = allNames.sort();
console.log(sortedNames);
// Problem 3
// The boss wants only the people with names that starts with a letter B because he thinks Ben is cool

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could have gone ahead and changed all names starting with B to BEN

Comment thread assignments/callbacks.js
return cb(arr[arr.length-1]);
// last passes the last item of the array into the callback.
}
last(items,function(lastItem){console.log(lastItem)});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last(items, console.log) will achieve the same results Note the lack of parens after log, this is intentional. We are passing the log function itself as the callback to last

Comment thread assignments/callbacks.js
last(items,function(lastItem){console.log(lastItem)});

function sumNums(x, y, cb) {
return cb(x+y);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding spaces between operators and variables will aid in readability.

Comment thread assignments/callbacks.js
multiplyNums(1,2,function(product){
console.log(product);
});
function contains(item, list, cb) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. This function does not work. The following code however would work

function contains(item, list, cb) {
  
  for(let i = 0; i < list.length; i++) {
    if(list[i] === item) {
      return cb(true);
    }
  }

  return cb(false);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants