-
Notifications
You must be signed in to change notification settings - Fork 0
5-7-19 Javascript II project #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
8ca8ceb
c38c166
583b27f
42ac8fb
c1bd006
c572226
f8f65cd
02f953c
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation. | ||
| // A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. | ||
| //Each business has assigned a representative to attend the event along with a small donation. | ||
|
|
||
| // Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses. | ||
|
|
||
|
|
@@ -55,29 +56,128 @@ 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 = []; | ||
| console.log(fullName); | ||
|
|
||
| // let fullName = []; | ||
| // for (let i = 0; i < runners.length; i++) { | ||
| // fullName.push(runners[i].first_name + " " + runners[i].last_name) | ||
| // } | ||
| // console.log(fullName) | ||
|
|
||
|
|
||
| let fullName2 = [] | ||
| runners.forEach(runner => fullName2.push(`${runner.first_name} ${runner.last_name}`)) | ||
| console.log(fullName2); | ||
|
Collaborator
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 using Template string literals here to render the name information from the runner object. This could also be done using string concatenation as well. |
||
|
|
||
|
|
||
| let fullName4 = [] | ||
| runners.forEach(addName) | ||
|
|
||
| function addName(word){ | ||
| fullName4.push(`${word.first_name} ${word.last_name}`) | ||
|
Collaborator
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. Nice abstracting the callback into its own function rather than typing it in the |
||
| } | ||
|
|
||
| console.log(fullName4) | ||
|
|
||
|
|
||
|
|
||
| // ==== 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 = []; | ||
| console.log(allCaps); | ||
|
|
||
| // let allCaps = []; | ||
| let allCaps = runners.map(allCapMode) | ||
|
|
||
| function allCapMode (words) { | ||
| return words.first_name.toUpperCase() | ||
| // allCaps.push(`${wubba.first_name}`) | ||
|
Collaborator
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. Glad to see it looks like you have a fairly solid grasp on callbacks now! |
||
| } | ||
|
|
||
|
|
||
|
|
||
| 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 = []; | ||
| // 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 = runners.filter(shirts).map(names) | ||
|
|
||
|
Collaborator
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. Nice use of Method chaining here, using dual abstracted callback functions stored in the global scope as their arguments! |
||
| function shirts(words){ | ||
| if (words.shirt_size === "L") { | ||
| return true | ||
| } | ||
| else { | ||
| return false | ||
| } | ||
| } | ||
|
Collaborator
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. Why not use the |
||
|
|
||
| function names(xxx) { | ||
| return xxx.first_name + " - " + xxx.shirt_size | ||
| } | ||
|
|
||
|
Collaborator
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. Naming convention! what is the Because of method chaining we. in this case, are iterating through the freshly filtered array of runners with a shirt size of large. So this |
||
| console.log(largeShirts); | ||
|
|
||
|
|
||
| // ==== 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 = []; | ||
|
|
||
|
|
||
|
|
||
| let ticketPriceTotal = runners.reduce(sums, 0) | ||
|
|
||
| function sums(x, y) { | ||
| return x + y.donation | ||
| } | ||
|
Collaborator
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. In reducers, you are better off sticking to keeping the actual callback inside of your |
||
|
|
||
| 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. | ||
| // 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 | ||
|
|
||
| //use map to list donation amounts | ||
|
|
||
| let newDonations = runners.map(tally) | ||
|
|
||
| function tally (jolly) { | ||
| return jolly.donation | ||
| } | ||
|
Collaborator
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. Naming convention. |
||
|
|
||
| console.log(newDonations) | ||
|
|
||
| // Problem 2 | ||
|
|
||
| // Problem 3 | ||
| // use map to scrape the array to sell people's information - our customer needs first name, last name, and email addresses | ||
|
|
||
|
|
||
| let cashflow = [] | ||
| runners.forEach(dollars) | ||
|
|
||
| function dollars (cash) { | ||
| cashflow.push(`To: ${cash.email} <br><br> Hello, Mr or Ms ${cash.first_name} ${cash.last_name}, we have an exciting offer for you today`) | ||
| } | ||
|
|
||
|
Collaborator
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. the breaks are HTML tags not JS . |
||
| console.log(cashflow) | ||
|
|
||
| // Problem 3 | ||
| // Our research shows only people who work at companies that donated over $150 fall for this. | ||
| // Filter them out, then give us an organized list of the their names, emails, and how much they gave. | ||
| // We don't need their shirt size | ||
|
|
||
| let suckers = runners.filter(haha).map(dollaBillsRain) | ||
|
|
||
| function haha(lol) { | ||
| if (lol.donation > 150) | ||
| return lol.first_name + lol.last_name + lol.email + lol.donation | ||
| } | ||
|
Collaborator
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. What is happening here with these names?!?! |
||
|
|
||
| function dollaBillsRain (payday) { | ||
| return (`${payday.first_name} ${payday.last_name} - ${payday.email} - $${payday.donation}`) | ||
| } | ||
|
|
||
| console.log(suckers) | ||
|
|
||
|
|
||
|
|
||
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.
I like seeing that you got both syntax's here.