Skip to content

Commit 5737921

Browse files
committed
Completed array-methods challenges
1 parent 6f4e273 commit 5737921

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

assignments/array-methods.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
// Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.
44

5-
const runners = [{
6-
"id": 1,
7-
"first_name": "Charmain",
8-
"last_name": "Seiler",
9-
"email": "[email protected]",
10-
"shirt_size": "2XL",
11-
"company_name": "Divanoodle",
12-
"donation": 75
13-
},
5+
const runners = [
6+
{
7+
"id": 1,
8+
"first_name": "Charmain",
9+
"last_name": "Seiler",
10+
"email": "[email protected]",
11+
"shirt_size": "2XL",
12+
"company_name": "Divanoodle",
13+
"donation": 75
14+
},
1415
{
1516
"id": 2,
1617
"first_name": "Whitaker",
@@ -481,7 +482,20 @@ console.log(ticketPriceTotal);
481482
// 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.
482483

483484
// Problem 1
485+
// List of emails we will send endless spam to
486+
487+
const bottomFiveDonors = runners.sort((a, b) => a.donation - b.donation).slice(0, 5).map(runner => runner.email);
488+
console.log(bottomFiveDonors);
484489

485490
// Problem 2
491+
// Names of runners whose names will not fit on their bibs. They will need to legally shorten their names in order to compete.
492+
493+
const fullNames = runners.map(runner => `${runner.first_name} ${runner.last_name}`);
494+
const longNames = fullNames.filter(name => name.length > 18);
495+
console.log(longNames);
496+
497+
// Problem 3
486498

487-
// Problem 3
499+
// Fix race so highest donation wins
500+
const winner = runners.sort((a, b) => b.donation - a.donation).slice(0, 1).map(runner => `${runner.first_name} ${runner.last_name}`);
501+
console.log(`Congratulations ${winner}!`);

0 commit comments

Comments
 (0)