Skip to content

Commit 2b327a5

Browse files
committed
added arrray-method solution
1 parent 770541a commit 2b327a5

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

assignments/array-methods.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.
1+
// A local community center is holding a fund raising 5k fun run and has invited 50 small
2+
// businesses to make a small donation on their behalf for some much needed updates to their facilities.
3+
// Each business has assigned a representative to attend the event along with a small donation.
24

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

@@ -54,27 +56,45 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5456
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];
5557

5658
// ==== Challenge 1: Use .forEach() ====
57-
// 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.
59+
// The event director needs both the first and last names of each runner for their running bibs.
60+
// Combine both the first and last names into a new array called fullName.
5861
let fullName = [];
59-
console.log(fullName);
62+
runners.forEach((key)=>{
63+
fullName.push(`${key.first_name} ${key.last_name}`)
64+
})
65+
// console.log(fullName);
6066

6167
// ==== Challenge 2: Use .map() ====
62-
// 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
68+
// The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER.
69+
// Convert each first name into all caps and log the result
6370
let allCaps = [];
64-
console.log(allCaps);
71+
allCaps = runners.map(all =>{
72+
return all.first_name.toUpperCase();
73+
})
74+
// console.log(allCaps);
6575

6676
// ==== Challenge 3: Use .filter() ====
67-
// 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
77+
// The large shirts won't be available for the event due to an ordering issue.
78+
// Get a list of runners with large sized shirts so they can choose a different size.
79+
//Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
6880
let largeShirts = [];
69-
console.log(largeShirts);
81+
largeShirts = runners.filter(all =>{
82+
return all.shirt_size === 'L';
83+
})
84+
// 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((a,b)=> a.donation + b.donation);
91+
ticketPriceTotal = runners.reduce(function (acc, obj) { return acc + obj.donation; }, 0);
7492
console.log(ticketPriceTotal);
7593

7694
// ==== Challenge 5: Be Creative ====
77-
// 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.
95+
// Now that you have used .forEach(), .map(), .filter(), and .reduce().
96+
// I want you to think of potential problems you could solve given the data set and the 5k fun run theme.
97+
// Try to create and then solve 3 unique problems using one or many of the array methods listed above.
7898

7999
// Problem 1
80100

assignments/callbacks.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Create a higher order function and invoke the callback function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.
1+
// Create a higher order function and invoke the callback function to test your work.
2+
// You have been provided an example of a problem and a solution to see how this works with our items array.
3+
// Study both the problem and the solution to figure out the rest of the problems.
24

3-
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
5+
const items = ["Pencil", "Notebook", "yo-yo", "Gum"];
46

57
/*
68
@@ -24,7 +26,6 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2426
2527
*/
2628

27-
2829
function getLength(arr, cb) {
2930
// getLength passes the length of the array into the callback.
3031
}

0 commit comments

Comments
 (0)