Repository navigation
finished callbacks - #1
SirAndrewDillon wants to merge 3 commits into
Conversation
Ian84Be
left a comment
There was a problem hiding this comment.
great job working through these. remember to make use of your ES6 syntax to keep your functions uncluttered.
| // } | ||
| // console.log(fullName); | ||
|
|
||
| runners.forEach(function(names){ |
There was a problem hiding this comment.
perfect way to do this. you could also refactor this to ES6 fat arrow syntax.
runners.forEach(names =>
fullName.push(`${names.first_name} ${names.last_name}`)
);
| // The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result | ||
| let largeShirts = []; | ||
|
|
||
| largeShirts = runners.filter(shirt => shirt.shirt_size === 'L') |
There was a problem hiding this comment.
excellent use of the fat arrow.
| // The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result | ||
| let ticketPriceTotal = []; | ||
|
|
||
| ticketPriceTotal = runners.reduce(function(ticket,item){ |
There was a problem hiding this comment.
this could also be refactored into ES6
ticketPriceTotal = runners.reduce((ticket,item) =>
ticket += item.donation, 0);
| // ==== Challenge 1: Write your own closure ==== | ||
| // Write a simple closure of your own creation. Keep it simple! | ||
|
|
||
| function sayHello(name) { |
There was a problem hiding this comment.
good job with this. you could also strip it down a bit more, the template literal does not require parens, and you can drop the curly braces from the say function.
function sayHello(name) {
const text = `Hello ${name}`;
const say = () => console.log(text);
say();
}
| const counter = () => { | ||
| // 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.
great job making use of javascript closure.
again you could make use of the ES6 syntax to clean up this function
const counter = () => {
let count = 0;
return () => ++count;
}
No description provided.