Repository navigation
Sofia levin: MVP #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
Changes from all commits
90cc0f0
3d819ff
e9664c4
2efd2ff
d0e9faa
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,112 @@ 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 = []; | ||
|
|
||
| runners.forEach(function(runners) { | ||
| fullName.push(runners.first_name + ' ' + runners.last_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(runners) { | ||
| return runners.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(function(runners) { | ||
| return runners.shirt_size === 'L' | ||
| }) | ||
|
|
||
| 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 = []; | ||
|
|
||
| ticketPriceTotal.push(runners.reduce(function(total, runners) { | ||
| return total += runners.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 - Large donors | ||
|
|
||
| let largeDonors = []; | ||
|
|
||
| largeDonors = runners.filter(function(runner) { | ||
| return runner.donation > 250 | ||
| }) | ||
|
|
||
| let largeDonorsEmails = []; | ||
|
|
||
| largeDonorsEmails = largeDonors.map(function(donor) { | ||
| return donor.email | ||
| }) | ||
|
|
||
| console.log(largeDonorsEmails); | ||
|
|
||
| // Problem 2 | ||
|
|
||
| // Problem 3 | ||
| let xsShirts = 0; | ||
| let sShirts = 0; | ||
| let mShirts = 0; | ||
| let lShirts = 0; | ||
| let xlShirts = 0; | ||
| let xxlShirts = 0; | ||
| let xxxlShirts = 0; | ||
|
|
||
| let totalTshirts = []; | ||
|
|
||
| runners.forEach(function(runner) { | ||
| if (runner.shirt_size === "XS") { | ||
| xsShirts += 1; | ||
| } else if (runner.shirt_size === "S") { | ||
| sShirts += 1; | ||
| } else if (runner.shirt_size === "M") { | ||
| mShirts += 1; | ||
| } else if (runner.shirt_size === "L") { | ||
| lShirts += 1; | ||
| } else if (runner.shirt_size === "XL") { | ||
| xlShirts += 1; | ||
| } else if (runner.shirt_size === "2XL") { | ||
| xxlShirts += 1; | ||
| } else if (runner.shirt_size === "3XL") { | ||
| xxxlShirts += 1; | ||
| } | ||
| }) | ||
|
|
||
| totalTshirts.push("XS: " + xsShirts, "S: " + sShirts, "M: " + mShirts, "L: " + lShirts, "XL: " + xlShirts, "2XL: " + xxlShirts, "3XL: " + xxxlShirts) | ||
| console.log(totalTshirts) | ||
|
|
||
|
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. good job going above and beyond what you needed to do |
||
| // Problem 3 | ||
|
|
||
| let companiesList = []; | ||
|
|
||
| companiesList = runners.map(function(item) { | ||
| return item.company_name | ||
| }) | ||
|
|
||
| companiesList.sort(); | ||
|
|
||
| let newArr = [companiesList[0]]; | ||
|
|
||
| for (let i = 1; i < companiesList.length - 1; i++) { | ||
| if (companiesList[i] !== companiesList[i - 1]) { | ||
| newArr.push(companiesList[i]); | ||
| } | ||
| } | ||
|
|
||
| console.log(newArr) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,28 +24,52 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; | |
|
|
||
| */ | ||
|
|
||
|
|
||
| function getLength(arr, cb) { | ||
| // getLength passes the length of the array into the callback. | ||
| return cb(arr.length); | ||
| } | ||
|
|
||
| getLength(items, function(length) { | ||
| console.log(length); | ||
| }) | ||
|
|
||
| function last(arr, cb) { | ||
| // last passes the last item of the array into the callback. | ||
| return cb(arr[arr.length - 1]); | ||
| } | ||
|
|
||
| last(items, function(lastItem) { | ||
| console.log(lastItem) | ||
| }) | ||
|
|
||
| function sumNums(x, y, cb) { | ||
| // sumNums adds two numbers (x, y) and passes the result to the callback. | ||
| return cb(x + y) | ||
| } | ||
|
|
||
| sumNums(3, 4, function(result) { | ||
| console.log(result) | ||
| }) | ||
|
|
||
| function multiplyNums(x, y, cb) { | ||
| // multiplyNums multiplies two numbers and passes the result to the callback. | ||
| return cb(x * y); | ||
| } | ||
|
|
||
| multiplyNums(3, 5, function (result) { | ||
| console.log(result); | ||
| }) | ||
|
|
||
| function contains(item, list, cb) { | ||
| // contains checks if an item is present inside of the given array/list. | ||
| // Pass true to the callback if it is, otherwise pass false. | ||
| return cb(list.include(item)) | ||
| } | ||
|
|
||
| contains('Gum', items, function(result) { | ||
| console.log(result); | ||
| }) | ||
|
|
||
|
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. function contains(item, list, cb) { contains('Bats', items, function(flag) { contains('Notebook', items, function(flag) { |
||
| /* STRETCH PROBLEM */ | ||
|
|
||
| function removeDuplicates(array, cb) { | ||
|
|
||
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.
great job, I would encourage you to look at string template literals