Skip to content

finished callbacks #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

finished callbacks #1

wants to merge 3 commits into from

Conversation

SirAndrewDillon
Copy link
Owner

No description provided.

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

@Ian84Be Ian84Be left a comment

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

console.log(allCaps);

// ==== Challenge 3: Use .filter() ====
// 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
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
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);

@@ -1,21 +1,43 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

function sayHello(name) {
Copy link
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();
}


/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */


// ==== Challenge 2: Create a counter function ====
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
let count = 0;
return(function() { return( ++count); })
Copy link
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