Skip to content

Commit aaabcea

Browse files
committed
array-methods 4/5 challenges completed
1 parent 9839820 commit aaabcea

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

assignments/array-methods.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,41 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5656
// ==== Challenge 1: Use .forEach() ====
5757
// 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.
5858
let fullName = [];
59+
60+
runners.forEach(function(runners){
61+
fullName.push(`${runners.first_name} ${runners.last_name}`);
62+
});
63+
5964
console.log(fullName);
6065

6166
// ==== Challenge 2: Use .map() ====
6267
// 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
6368
let allCaps = [];
69+
70+
allCaps = runners.map(function(runners){
71+
return runners.first_name.toUpperCase();
72+
});
73+
6474
console.log(allCaps);
6575

6676
// ==== Challenge 3: Use .filter() ====
6777
// 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
6878
let largeShirts = [];
79+
80+
largeShirts = runners.filter(function(runners){
81+
return runners.shirt_size === "L";
82+
});
83+
6984
console.log(largeShirts);
7085

7186
// ==== Challenge 4: Use .reduce() ====
7287
// 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
7388
let ticketPriceTotal = [];
89+
90+
ticketPriceTotal = runners.reduce(function(totalDonation, runners){
91+
return totalDonation += runners.donation;
92+
}, 0);
93+
7494
console.log(ticketPriceTotal);
7595

7696
// ==== Challenge 5: Be Creative ====

assignments/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script src="array-methods.js"></script>
1111
<script src="callbacks.js"></script>
1212
<script src="closure.js"></script>
13-
<script src="stretch-function-conversion.js"></script>
13+
<!-- <script src="stretch-function-conversion.js"></script> -->
1414
</head>
1515

1616
<body>

0 commit comments

Comments
 (0)