WEBEU2 - JavaScript-II - Isaac Aderogba 🇮🇪 - #1
Conversation
maximesalomon
left a comment
There was a problem hiding this comment.
Good job on this Isaac 👍 Seems like you have a pretty good understanding of array methods, callbacks, and closures!
You had one exercise were you misread the question. Try to fix that when you have some time.
| let fullName = []; | ||
| const fullName = []; | ||
|
|
||
| runners.forEach(element => { |
There was a problem hiding this comment.
Try to use a more descriptive name than element when using array methods --> runner could be a good name here
| // The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result | ||
| let allCaps = []; | ||
| // Explicit approach | ||
| const allCaps = runners.map(function(element) { |
There was a problem hiding this comment.
why not use ES6 arrow function?
| let largeShirts = []; | ||
| const largeShirts = runners.filter(function(element) { | ||
| return element.shirt_size === "L" | ||
| }); |
There was a problem hiding this comment.
ES6 array function are cleaner, start to use them:
--> const largeShirts = runners.filter(runner => runner.shirt_size === "L");
| } | ||
|
|
||
| last(items, function(lastItem) { | ||
| console.log("Q2 Callbacks: " + lastItem); |
There was a problem hiding this comment.
Read the question again
There was a problem hiding this comment.
It says "last passes the last item of the array into the callback".
The code below passes the last item of the array into the callback:
return cb(**arr.length - 1**);
Where have I misunderstood that?
|
|
||
| /* STRETCH PROBLEM */ | ||
|
|
||
| function removeDuplicates(array, cb) { |
There was a problem hiding this comment.
Good job doing the stretch!
| // ==== Challenge 1: Write your own closure ==== | ||
| // Write a simple closure of your own creation. Keep it simple! | ||
|
|
||
| function whoLikesIceCream(yourName) { |
| // Return a function that when invoked increments and returns a counter variable. | ||
| let count = 0; | ||
| return function() { | ||
| return ++count; |
There was a problem hiding this comment.
What's the difference between ++count and count++?
No description provided.