Skip to content

Commit 6d7b07a

Browse files
Naaz ShaikhNaaz Shaikh
authored andcommitted
arrays done
1 parent 5978e3f commit 6d7b07a

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

assignments/array-methods.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,61 @@ 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);
58+
59+
let fullName =[]
60+
runners.forEach(x => {
61+
let name = (x.first_name);
62+
let surname= (x.last_name);
63+
fullName.push(name.concat(" " + surname));
64+
})
65+
console.log(fullName);
66+
67+
6068

6169
// ==== Challenge 2: Use .map() ====
6270
// 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
6371
let allCaps = [];
72+
73+
runners.map (x=> {
74+
let name = (x.first_name.toUpperCase())
75+
allCaps.push(name);
76+
})
6477
console.log(allCaps);
6578

79+
80+
81+
82+
6683
// ==== Challenge 3: Use .filter() ====
6784
// 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
6885
let largeShirts = [];
69-
console.log(largeShirts);
86+
largeShirts = runners.filter (runner => runner.shirt_size === "L")
87+
console.log(largeShirts)
88+
89+
// let largeShirts = [];
90+
// largeShirts = runners.filter (runner => {
91+
// if(runner.shirt_size === "L"){
92+
// return true;
93+
// }
94+
// else {
95+
// return false;
96+
// }
97+
// })
98+
// console.log(largeShirts)
99+
100+
70101

71102
// ==== Challenge 4: Use .reduce() ====
72103
// 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
73104
let ticketPriceTotal = [];
105+
runners.forEach(x => {
106+
let ticketPrice = (x.donation);
107+
ticketPriceTotal.push(ticketPrice);
108+
})
109+
110+
ticketPriceTotal = ticketPriceTotal.reduce ((acc,x ) => acc + x)
111+
112+
74113
console.log(ticketPriceTotal);
75114

76115
// ==== Challenge 5: Be Creative ====

0 commit comments

Comments
 (0)