Skip to content

Commit 3450eca

Browse files
Merge pull request #1 from sofialevin/sofia-levin
Sofia levin: MVP
2 parents bc4a039 + d0e9faa commit 3450eca

3 files changed

Lines changed: 127 additions & 3 deletions

File tree

‎assignments/array-methods.js‎

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,112 @@ 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+
60+
runners.forEach(function(runners) {
61+
fullName.push(runners.first_name + ' ' + runners.last_name)
62+
})
63+
5964
console.log(fullName);
6065

6166
// ==== Challenge 2: Use .map() ====
6267
// 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
6368
let allCaps = [];
69+
70+
allCaps = runners.map(function(runners) {
71+
return runners.first_name.toUpperCase();
72+
})
73+
6474
console.log(allCaps);
6575

6676
// ==== Challenge 3: Use .filter() ====
6777
// 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
78+
6879
let largeShirts = [];
80+
81+
largeShirts = runners.filter(function(runners) {
82+
return runners.shirt_size === 'L'
83+
})
84+
6985
console.log(largeShirts);
7086

7187
// ==== Challenge 4: Use .reduce() ====
7288
// 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
7389
let ticketPriceTotal = [];
90+
91+
ticketPriceTotal.push(runners.reduce(function(total, runners) {
92+
return total += runners.donation
93+
}, 0))
94+
7495
console.log(ticketPriceTotal);
7596

7697
// ==== Challenge 5: Be Creative ====
7798
// 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.
7899

79-
// Problem 1
100+
// Problem 1 - Large donors
101+
102+
let largeDonors = [];
103+
104+
largeDonors = runners.filter(function(runner) {
105+
return runner.donation > 250
106+
})
107+
108+
let largeDonorsEmails = [];
109+
110+
largeDonorsEmails = largeDonors.map(function(donor) {
111+
return donor.email
112+
})
113+
114+
console.log(largeDonorsEmails);
80115

81116
// Problem 2
82117

83-
// Problem 3
118+
let xsShirts = 0;
119+
let sShirts = 0;
120+
let mShirts = 0;
121+
let lShirts = 0;
122+
let xlShirts = 0;
123+
let xxlShirts = 0;
124+
let xxxlShirts = 0;
125+
126+
let totalTshirts = [];
127+
128+
runners.forEach(function(runner) {
129+
if (runner.shirt_size === "XS") {
130+
xsShirts += 1;
131+
} else if (runner.shirt_size === "S") {
132+
sShirts += 1;
133+
} else if (runner.shirt_size === "M") {
134+
mShirts += 1;
135+
} else if (runner.shirt_size === "L") {
136+
lShirts += 1;
137+
} else if (runner.shirt_size === "XL") {
138+
xlShirts += 1;
139+
} else if (runner.shirt_size === "2XL") {
140+
xxlShirts += 1;
141+
} else if (runner.shirt_size === "3XL") {
142+
xxxlShirts += 1;
143+
}
144+
})
145+
146+
totalTshirts.push("XS: " + xsShirts, "S: " + sShirts, "M: " + mShirts, "L: " + lShirts, "XL: " + xlShirts, "2XL: " + xxlShirts, "3XL: " + xxxlShirts)
147+
console.log(totalTshirts)
148+
149+
// Problem 3
150+
151+
let companiesList = [];
152+
153+
companiesList = runners.map(function(item) {
154+
return item.company_name
155+
})
156+
157+
companiesList.sort();
158+
159+
let newArr = [companiesList[0]];
160+
161+
for (let i = 1; i < companiesList.length - 1; i++) {
162+
if (companiesList[i] !== companiesList[i - 1]) {
163+
newArr.push(companiesList[i]);
164+
}
165+
}
166+
167+
console.log(newArr)

‎assignments/callbacks.js‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,52 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424
2525
*/
2626

27-
2827
function getLength(arr, cb) {
2928
// getLength passes the length of the array into the callback.
29+
return cb(arr.length);
3030
}
3131

32+
getLength(items, function(length) {
33+
console.log(length);
34+
})
35+
3236
function last(arr, cb) {
3337
// last passes the last item of the array into the callback.
38+
return cb(arr[arr.length - 1]);
3439
}
3540

41+
last(items, function(lastItem) {
42+
console.log(lastItem)
43+
})
44+
3645
function sumNums(x, y, cb) {
3746
// sumNums adds two numbers (x, y) and passes the result to the callback.
47+
return cb(x + y)
3848
}
3949

50+
sumNums(3, 4, function(result) {
51+
console.log(result)
52+
})
53+
4054
function multiplyNums(x, y, cb) {
4155
// multiplyNums multiplies two numbers and passes the result to the callback.
56+
return cb(x * y);
4257
}
4358

59+
multiplyNums(3, 5, function (result) {
60+
console.log(result);
61+
})
62+
4463
function contains(item, list, cb) {
4564
// contains checks if an item is present inside of the given array/list.
4665
// Pass true to the callback if it is, otherwise pass false.
66+
return cb(list.include(item))
4767
}
4868

69+
contains('Gum', items, function(result) {
70+
console.log(result);
71+
})
72+
4973
/* STRETCH PROBLEM */
5074

5175
function removeDuplicates(array, cb) {

‎assignments/closure.js‎

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

4+
function increase() {
5+
let num1 = 0;
6+
function add(num2) {
7+
num1 = num1 + num2
8+
return num1
9+
}
10+
return add
11+
}
12+
13+
const increment = increase();
14+
15+
const c1 = increment(2)
16+
const c2 = increment(3)
17+
const c3 = increment(5)
18+
19+
console.log(c1, c2, c3)
420

521
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
622

0 commit comments

Comments
 (0)