Skip to content

Commit 5ee4e04

Browse files
committed
everything done except challenge 5 of array-methods.js
1 parent a1dd794 commit 5ee4e04

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

assignments/array-methods.js

Lines changed: 12 additions & 0 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((data) => {
60+
fullName.push(data.first_name + ' ' + data.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
6366
let allCaps = [];
67+
allCaps = runners.map(function(data){
68+
return data.first_name.toUpperCase();
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
6874
let largeShirts = [];
75+
largeShirts = runners.filter((data) => {
76+
return data.shirt_size === 'M' || data.shirt_size === 'L';
77+
});
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
7382
let ticketPriceTotal = [];
83+
ticketPriceTotal = runners.reduce((acum, curr) => {
84+
return acum + curr.donation;
85+
}, 0);
7486
console.log(ticketPriceTotal);
7587

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

assignments/closure.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3-
3+
const myClosure = () => {
4+
let firstNam = 'David', lastName = 'Loveday';
5+
return () => {
6+
return 'my name is ' + firstNam + ' ' + lastName;
7+
};
8+
};
9+
let myclosure = myClosure();
10+
console.log(myclosure());
411

512
// ==== Challenge 2: Create a counter function ====
613
const counter = () => {
714
// Return a function that when invoked increments and returns a counter variable.
15+
let count = 0;
16+
return () => {
17+
return ++count
18+
};
819
};
20+
21+
let newCounter = counter();
922
// Example usage: const newCounter = counter();
10-
// newCounter(); // 1
11-
// newCounter(); // 2
23+
console.log(newCounter());
24+
console.log(newCounter());
1225

1326

1427
// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
1528
const counterFactory = () => {
29+
let counter = 0;
30+
const obj = {"increment": () =>{ return ++counter; }, "decrement": ()=> { return --counter; }};
1631
// Return an object that has two methods called `increment` and `decrement`.
1732
// `increment` should increment a counter variable in closure scope and return it.
1833
// `decrement` should decrement the counter variable and return it.

assignments/function-conversion.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
22

3-
// let myFunction = function () {};
3+
let myFunction = () => {};
44

5-
// let anotherFunction = function (param) {
6-
// return param;
7-
// };
5+
let anotherFunction = (param) => {
6+
return param;
7+
};
88

9-
// let add = function (param1, param2) {
10-
// return param1 + param2;
11-
// };
12-
// add(1,2);
9+
let add = (param1, param2) => {
10+
return param1 + param2;
11+
};
12+
console.log(add(1,2));
1313

14-
let subtract = function (param1, param2) {
14+
let subtract = (param1, param2) => {
1515
return param1 - param2;
1616
};
17-
subtract(1,2); //?
17+
console.log(subtract(1,2));
1818

1919
exampleArray = [1,2,3,4];
20-
// const triple = exampleArray.map(function (num) {
21-
// return num * 3;
22-
// });
23-
// console.log(triple);
20+
21+
const triple = exampleArray.map((num) => {
22+
return num * 3;
23+
});
24+
console.log(triple);

0 commit comments

Comments
 (0)