Skip to content

Commit 8b94e4b

Browse files
committed
completed array-methods.js and function-conversion.js
1 parent 3450a31 commit 8b94e4b

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

assignments/array-methods.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,33 @@ 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+
runners.forEach(function (runner) {
60+
fullName.push(runner.first_name + " " + runner.last_name);
61+
});
5962
console.log(fullName);
6063

6164
// ==== Challenge 2: Use .map() ====
6265
// 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
63-
let allCaps = [];
66+
let allCaps = runners.map(function(elem, index, array) {
67+
return elem.first_name.toUpperCase();
68+
});
69+
6470
console.log(allCaps);
6571

6672
// ==== Challenge 3: Use .filter() ====
6773
// 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
68-
let largeShirts = [];
74+
let largeShirts = runners.filter(function(elem, index, array) {
75+
return elem.shirt_size === "L";
76+
});
77+
console.log("this is for large shirts")
6978
console.log(largeShirts);
7079

7180
// ==== Challenge 4: Use .reduce() ====
7281
// 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
73-
let ticketPriceTotal = [];
82+
let ticketPriceTotal = runners.reduce(function(a, b){
83+
return a += b.donation;
84+
}, 0);
85+
console.log("ticket price total")
7486
console.log(ticketPriceTotal);
7587

7688
// ==== Challenge 5: Be Creative ====

assignments/closure.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
33

4+
const challenge1 = () => {
5+
6+
}
47

58
// ==== Challenge 2: Create a counter function ====
69
const counter = () => {

assignments/function-conversion.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22

33
// let myFunction = function () {};
44

5+
let myFunction = () => {};
6+
57
// let anotherFunction = function (param) {
68
// return param;
79
// };
810

11+
let anotherFunction = param => param;
12+
console.log(anotherFunction('hello'))
913
// let add = function (param1, param2) {
1014
// return param1 + param2;
1115
// };
1216
// add(1,2);
1317

18+
let add = (param1, param2) => param1 + param2;
19+
console.log(add(1,2));
1420
// let subtract = function (param1, param2) {
1521
// return param1 + param2;
1622
// };
1723
// subtract(1,2);
1824

25+
let subtract = (param1, param2) => param1 - param2;
26+
console.log(subtract(1,2));
27+
1928
exampleArray = [1,2,3,4];
2029
// const triple = exampleArray.map(function (num) {
2130
// return num * 3;
2231
// });
23-
// console.log(triple);
32+
// console.log(triple);
33+
34+
const triple = exampleArray.map(num => num + 3);
35+
console.log(triple);

0 commit comments

Comments
 (0)