-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,28 +56,121 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c | |
// ==== Challenge 1: Use .forEach() ==== | ||
// 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 = []; | ||
//i did the the old way for testing purposes | ||
// for(let i = 0; i < runners.length; i++){ | ||
// fullName.push(`${runners[i].first_name} ${runners[i].last_name}`); | ||
// } | ||
// console.log(fullName); | ||
|
||
runners.forEach(function(names){ | ||
|
||
fullName.push(`${names.first_name} ${names.last_name}`) | ||
//console.log(value.first_name) | ||
}); | ||
console.log(fullName); | ||
|
||
// ==== Challenge 2: Use .map() ==== | ||
// 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 = []; | ||
allCaps = runners.map(function(names) { | ||
return names.first_name.toUpperCase() | ||
}); | ||
|
||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent use of the fat arrow. |
||
|
||
console.log(largeShirts); | ||
|
||
// ==== Challenge 4: Use .reduce() ==== | ||
// // ==== Challenge 4: Use .reduce() ==== | ||
// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also be refactored into ES6
|
||
|
||
return ticket += item.donation; | ||
},0); | ||
|
||
console.log(ticketPriceTotal); | ||
|
||
// ==== Challenge 5: Be Creative ==== | ||
// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above. | ||
|
||
// Problem 1 | ||
// Problem 1: Find which company donated the most and output: companyName donationValue. | ||
let maxVal = 0; | ||
let biggestCompany = []; | ||
|
||
runners.forEach(function(value){ | ||
if(value.donation > maxVal){ | ||
maxVal = value.donation; | ||
} | ||
}); | ||
|
||
runners.filter(function(value){ | ||
if(value.donation === maxVal){ | ||
console.log(`${value.company_name} ${maxVal}`); | ||
return; | ||
} | ||
}); | ||
|
||
|
||
// Problem 2: if donations are over 50 dollars then gather the emails of the individuals to send a special thank you. | ||
let runnerMail = []; | ||
let runnerabv50 = []; | ||
runnerabv50 = runners.filter(function(value){ | ||
return value.donation > 50; | ||
}); | ||
|
||
|
||
runnerabv50.forEach(function(value){ | ||
|
||
runnerMail.push(`${value.email}`) | ||
|
||
}); | ||
console.log(runnerMail) | ||
|
||
// Find out who wears a size small in the list of runners. | ||
let sizeSmall = []; | ||
|
||
runners.filter((runner) => { | ||
|
||
if(runner.shirt_size === "S"){ | ||
|
||
sizeSmall.push(runner.first_name + " " + runner.last_name); | ||
} | ||
}); | ||
console.log(sizeSmall); | ||
|
||
// Problem 2 | ||
//The t-shirt supplier needs to know how many of each kind of shirt they will need to ship. Make an array for each size. | ||
let sCount = []; | ||
sCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === 'S'; | ||
}) | ||
let mCount = []; | ||
mCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === 'M'; | ||
}) | ||
let lCount = []; | ||
lCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === 'L'; | ||
}) | ||
let xlCount = []; | ||
xlCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === 'XL'; | ||
}) | ||
let xxlCount = []; | ||
xxlCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === '2XL'; | ||
}) | ||
let xxxlCount = []; | ||
xxxlCount = runners.filter((runner) =>{ | ||
return runner.shirt_size === '3XL'; | ||
}) | ||
|
||
console.log(`We will need ${sCount.length} small, ${mCount.length} medium, ${lCount.length} large, ${xlCount.length} xl, ${xxlCount.length} xxl, and ${xxxlCount.length} 3xl shirts.`); | ||
|
||
// Problem 3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
// ==== 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. Choose a reason for hiding this commentThe 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.
|
||
const text = (`Hello ${name}`); | ||
const say = function() { console.log(text); } | ||
say(); | ||
} | ||
sayHello('Andy'); | ||
|
||
/* 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); }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great job making use of javascript closure.
|
||
}; | ||
const newCounter = counter(); | ||
console.log(newCounter()); | ||
console.log(newCounter()); | ||
// Example usage: const newCounter = counter(); | ||
// newCounter(); // 1 | ||
// newCounter(); // 2 | ||
|
||
|
||
// ==== Challenge 3: Create a counter function with an object that can increment and decrement ==== | ||
const counterFactory = () => { | ||
// Return an object that has two methods called `increment` and `decrement`. | ||
// `increment` should increment a counter variable in closure scope and return it. | ||
// `decrement` should decrement the counter variable and return it. | ||
}; | ||
let counter = 0; | ||
object = { | ||
increment: function(){ | ||
return counter++; | ||
}, | ||
decrement: function(){ | ||
return counter--; | ||
} | ||
|
||
} | ||
}; |
There was a problem hiding this comment.
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.