Skip to content

Commit

Permalink
finished array methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Abott1222 committed Nov 27, 2018
1 parent e371a56 commit db6af5e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,32 @@ 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 Kick out the rich people by excluding donations larger than 200

// Problem 2
let remainingRunners = runners.filter( function(runnerObj) {
return runnerObj.donation < 200;
})

// Problem 2 combine everyones last name

const reducer2 = function(acc, runnerObj) {
return acc + runnerObj.last_name;
}

let hugeLastName = runners.reduce(reducer2, '');
console.log(hugeLastName);

// Problem 3 Get #s for each shirt size

let shirtSizeCount = {}

runners.forEach( function(runnerObj) {
let size = runnerObj.shirt_size;
if(!shirtSizeCount[size]) {
shirtSizeCount[runnerObj.shirt_size] = 1;
} else {
shirtSizeCount[runnerObj.shirt_size]++;
}
})

// Problem 3
console.log(JSON.stringify(shirtSizeCount));

0 comments on commit db6af5e

Please sign in to comment.