Skip to content

Commit c7b829e

Browse files
committed
array-methods
1 parent eafb104 commit c7b829e

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

assignments/array-methods.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,48 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5555

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.
58-
let fullName = [];
59-
console.log(fullName);
60-
console.log("Hello World");
58+
// let fullName = [];
59+
// console.log(fullName);
6160

6261

63-
for (i = 0; i < runners.length; i++){
64-
let fullName =[];
65-
fullName.push(runners[i].first_name);
66-
fullName.push(runners[i].last_name);
67-
console.log(fullName);
68-
}
62+
// for (i = 0; i < runners.length; i++){
63+
// let fullName =[];
64+
// fullName.push(runners[i].first_name);
65+
// fullName.push(runners[i].last_name);
66+
// console.log(fullName);
67+
// }
6968

70-
let i = 0;
71-
runners.forEach(function(first_name, last_name){
72-
73-
let fullName = [];
74-
fullName.push(runners[i].first_name, runners[i].last_name)
75-
console.log(fullName);
76-
i++;
77-
});
69+
runners.forEach(runner => {
70+
let fullName = [];
71+
fullName.push(runner.first_name, runner.last_name)
72+
console.log(fullName);
73+
});
7874

7975
// ==== Challenge 2: Use .map() ====
8076
// 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
81-
let i = 0;
8277
let allCaps = runners.map(capFirst => {
83-
console.log(runners[i].first_name.toUpperCase())
84-
i++;
85-
78+
console.log(capFirst.first_name.toUpperCase())
8679
});
8780

8881

8982
// ==== Challenge 3: Use .filter() ====
9083
// 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
91-
let largeShirts = [];
84+
// let largeShirts = [];
85+
const largeShirts = runners.filter(runner => runner.shirt_size === 'L' );
9286
console.log(largeShirts);
9387

9488
// ==== Challenge 4: Use .reduce() ====
9589
// 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
96-
let ticketPriceTotal = [];
97-
console.log(ticketPriceTotal);
90+
// let ticketPriceTotal = [];
91+
// const reducer = (accumulator, currentValue) => {
92+
// return accumulator + currentValue ;
93+
// console.log("donation")
94+
// };
95+
console.log(runners[1].donation)
96+
const ticketPriceTotal = runners.reduce((accumulator, runner) => {
97+
return accumulator += runner.donation;
98+
}, 0);
99+
console.log('ticket price total', ticketPriceTotal);
98100

99101
// ==== Challenge 5: Be Creative ====
100102
// Now that you have used .forEach(), .map(), .filter(), and .reduce().
@@ -103,6 +105,7 @@ console.log(ticketPriceTotal);
103105

104106
// Problem 1
105107

108+
106109
// Problem 2
107110

108111
// Problem 3

0 commit comments

Comments
 (0)