Skip to content

Commit 780b144

Browse files
committed
Project MVP completed
1 parent 1a0b619 commit 780b144

3 files changed

Lines changed: 92 additions & 5 deletions

File tree

assignments/array-methods.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,62 @@ 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-
console.log(fullName);
59+
runners.forEach( function(currentvalue){
60+
fullName.push(`${currentvalue.first_name} ${currentvalue.last_name}`);
61+
});
62+
63+
console.log(fullName)
6064

6165
// ==== Challenge 2: Use .map() ====
6266
// 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 = [];
67+
let allCaps = runners.map(function(currentvalue){
68+
return currentvalue.first_name.toUpperCase();
69+
});
70+
6471
console.log(allCaps);
6572

6673
// ==== Challenge 3: Use .filter() ====
6774
// 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 = [];
75+
let largeShirts = runners.filter(function(currentvalue){
76+
return currentvalue.shirt_size == 'L'; /* Different way--> .includes('L') && !currentvalue.shirt_size.includes('XL');*/
77+
});
78+
79+
6980
console.log(largeShirts);
7081

7182
// ==== Challenge 4: Use .reduce() ====
7283
// 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 = [];
84+
let ticketPriceTotal = runners.reduce(function(accumulator, currentvalue){
85+
return accumulator + currentvalue.donation;
86+
},0);
87+
88+
7489
console.log(ticketPriceTotal);
7590

7691
// ==== Challenge 5: Be Creative ====
7792
// 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.
7893

7994
// Problem 1
95+
//.forEach(), runners names and email emails
96+
const nameandemail = [];
97+
98+
runners.forEach(function(currentvalue){
99+
nameandemail.push(`${currentvalue.first_name} ${currentvalue.last_name}: ${currentvalue.email}`);
100+
});
101+
console.log(nameandemail);
80102

81103
// Problem 2
104+
//.map(), names and donations
105+
const namesAnd = runners.map(function(currentvalue){
106+
return `${currentvalue.first_name} ${currentvalue.last_name} Donated: $${currentvalue.donation}`
107+
});
108+
109+
console.log(namesAnd);
110+
// Problem 3
111+
112+
//.filter, donations under 100$
113+
const Under100 = runners.filter(function(currentvalue){
114+
return currentvalue.donation < 100;
115+
})
82116

83-
// Problem 3
117+
console.log(Under100);

assignments/callbacks.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,64 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2626

2727

2828
function getLength(arr, cb) {
29+
return cb(arr.length);
2930
// getLength passes the length of the array into the callback.
3031
}
3132

33+
getLength(items, function(length){
34+
console.log(length);
35+
});
36+
3237
function last(arr, cb) {
38+
return cb(arr[arr.length-1]);
3339
// last passes the last item of the array into the callback.
3440
}
3541

42+
last(items, function(lastitem){
43+
console.log(lastitem);
44+
});
45+
3646
function sumNums(x, y, cb) {
47+
return cb(x + y);
3748
// sumNums adds two numbers (x, y) and passes the result to the callback.
3849
}
3950

51+
sumNums(5, 3, function(add){
52+
console.log(add);
53+
});
54+
4055
function multiplyNums(x, y, cb) {
56+
return cb(x * y);
4157
// multiplyNums multiplies two numbers and passes the result to the callback.
4258
}
4359

60+
multiplyNums(5, 8, function(multiply){
61+
console.log(multiply);
62+
})
63+
4464
function contains(item, list, cb) {
65+
if (list.includes(item)) {
66+
return cb(true);
67+
}else{
68+
return cb(false);
69+
}
4570
// contains checks if an item is present inside of the given array/list.
4671
// Pass true to the callback if it is, otherwise pass false.
4772
}
4873

74+
contains('Notebook', items, function(contain){
75+
console.log(contain);
76+
});
77+
78+
79+
80+
4981
/* STRETCH PROBLEM */
5082

5183
function removeDuplicates(array, cb) {
5284
// removeDuplicates removes all duplicate values from the given array.
5385
// Pass the duplicate free array to the callback function.
5486
// Do not mutate the original array.
5587
}
88+
89+

assignments/closure.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
// Write a simple closure of your own creation. Keep it simple!
33

44

5+
function myClosure() {
6+
console.log('this is my closure example');
7+
const message = "This is my message from within myClosure";
8+
9+
function secondClosure() {
10+
console.log(`example: ${message}`);
11+
const anothermessage = 'This is another message from within my secondClosure';
12+
13+
function thirdClosure() {
14+
console.log(`${message} and ${anothermessage}`)
15+
}
16+
thirdClosure();
17+
}
18+
secondClosure();
19+
}
20+
myClosure();
21+
22+
23+
524
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
625

726

0 commit comments

Comments
 (0)