Skip to content

finished callbacks - #1

Open
SirAndrewDillon wants to merge 3 commits into
masterfrom
andy-dillon
Open

finished callbacks#1
SirAndrewDillon wants to merge 3 commits into
masterfrom
andy-dillon

Conversation

@SirAndrewDillon

Copy link
Copy Markdown
Owner

No description provided.

@SirAndrewDillon
SirAndrewDillon requested a review from Ian84Be May 7, 2019 20:41

@Ian84Be Ian84Be left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this could also be refactored into ES6

ticketPriceTotal = runners.reduce((ticket,item) => 
  ticket += item.donation, 0);

Comment thread assignments/closure.js
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

function sayHello(name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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();
}

Comment thread assignments/closure.js
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
let count = 0;
return(function() { return( ++count); })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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; 
}

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.

2 participants