Conversation
…elpixel-patch-1 Patrick Kennedy
…patch-1 Typo Fix.
ashwins93
reviewed
Oct 17, 2018
| // 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}`); |
| // 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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
you could have gone ahead and changed all names starting with B to BEN
| return cb(arr[arr.length-1]); | ||
| // last passes the last item of the array into the callback. | ||
| } | ||
| last(items,function(lastItem){console.log(lastItem)}); |
There was a problem hiding this comment.
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
| last(items,function(lastItem){console.log(lastItem)}); | ||
|
|
||
| function sumNums(x, y, cb) { | ||
| return cb(x+y); |
There was a problem hiding this comment.
Adding spaces between operators and variables will aid in readability.
| multiplyNums(1,2,function(product){ | ||
| console.log(product); | ||
| }); | ||
| function contains(item, list, cb) { |
There was a problem hiding this comment.
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);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.