Skip to content

Commit 9682ab5

Browse files
committed
array done
1 parent 2157943 commit 9682ab5

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎assignments/array-methods.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,24 @@ console.log(fullName);
6464
// ==== Challenge 2: Use .map() ====
6565
// 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
6666
let allCaps = [];
67+
runners.map(function (firstName){
68+
allCaps.push(firstName.first_name.toUpperCase());
69+
});
6770
console.log(allCaps);
6871

6972
// ==== Challenge 3: Use .filter() ====
7073
// 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
71-
let largeShirts = [];
74+
let largeShirts = runners.filter(function(runner){
75+
return runner.shirt_size == 'L';
76+
});
7277
console.log(largeShirts);
7378

7479
// ==== Challenge 4: Use .reduce() ====
7580
// 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
76-
let ticketPriceTotal = [];
81+
let ticketPriceTotal = runners.reduce((accumulator, currentValue) => {
82+
return accumulator + currentValue.donation;
83+
}, 0); //The first time the function is called, it gets called with (0, {donation: 75 }) and returns 0 + 75 = 75. Then adds the rest the same way.
84+
7785
console.log(ticketPriceTotal);
7886

7987
// ==== Challenge 5: Be Creative ====

‎assignments/closure.js‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3-
3+
function name(){
4+
let name = 'Dionuta';
5+
function addLastName () {
6+
const lastName = 'Burton'
7+
console.log(`${name} ${lastName}`)
8+
}
9+
addLastName();
10+
}
11+
name();
412

513
// ==== Challenge 2: Create a counter function ====
614
const counter = () => {
7-
// Return a function that when invoked increments and returns a counter variable.
8-
};
9-
// Example usage: const newCounter = counter();
10-
// newCounter(); // 1
11-
// newCounter(); // 2
15+
// Return a function that when invoked increments and returns a counter variable.f
16+
let count = 1;
17+
return function() {
18+
return count++;
19+
};
20+
}
21+
22+
23+
const newCounter = counter();
24+
console.log(newCounter()); // 1
25+
console.log(newCounter())// 2
1226

1327
/* STRETCH PROBLEM, Do not attempt until you have completed all previous tasks for today's project files */
1428

0 commit comments

Comments
 (0)