Skip to content

Commit 67883b1

Browse files
committed
mvp commit
1 parent 770541a commit 67883b1

5 files changed

Lines changed: 68 additions & 24 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ We have learned that closures allow us to access values in scope that have alrea
5050
## Stretch Goals
5151

5252
* [ ] Go back through the stretch problems that you skipped over and complete as many as you can.
53-
* [ ] Look up what an IIFE is in JavaScript and experiment with them
53+
* [ ] Look up what an IIFE is in JavaScript and experiment with them
54+
55+
https://codepen.io/bpatton/pen/zQxpeQ?editors=0011
56+
https://codepen.io/bpatton/pen/mYypoR?editors=0011
57+
https://codepen.io/bpatton/pen/KLwZEB?editors=1011

‎assignments/array-methods.js‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,41 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5555

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.
58-
let fullName = [];
59-
console.log(fullName);
58+
let fullName = runners.map(k => [k.first_name,k.last_name].join(" "));
59+
console.log(fullName.slice(0,5));
6060

6161
// ==== Challenge 2: Use .map() ====
6262
// 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 = [];
64-
console.log(allCaps);
63+
64+
let allCaps = runners.map(k => k.first_name.toUpperCase())
65+
console.log(allCaps.slice(0,5));
6566

6667
// ==== Challenge 3: Use .filter() ====
6768
// 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 = [];
69-
console.log(largeShirts);
69+
let largeShirts = runners.filter(k => k.shirt_size =="L");
70+
console.log(largeShirts.slice(0,5));
7071

7172
// ==== Challenge 4: Use .reduce() ====
7273
// 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 = [];
74+
let ticketPriceTotal = runners.reduce((ac,r) => {return ac += r.donation;},0);
7475
console.log(ticketPriceTotal);
7576

7677
// ==== Challenge 5: Be Creative ====
7778
// 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.
7879

7980
// Problem 1
81+
let emailList = runners
82+
// .map( k => runners[k] )
83+
// .map(k => k.email)
84+
.filter(k => k.shirt_size =="L");
85+
console.log(emailList.slice(0-5));
8086

8187
// Problem 2
88+
let donationsByCompay = runners.reduce(
89+
(ac,p) => ({...ac, [p.company_name]: p.donation +p.donation }), {} )
8290

83-
// Problem 3
91+
console.log(donationsByCompay);
92+
93+
// Problem 3
94+
let tshirtsBySize = runners.reduce((ac,r) => ({...ac,[r.shirt_size]: (ac[r.shirt_size] || 0)+1}),{});
95+
console.log(tshirtsBySize);

‎assignments/callbacks.js‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
44

5-
/*
6-
75
//Given this problem:
86

97
function firstItem(arr, cb) {
@@ -22,34 +20,59 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2220
console.log(first)
2321
});
2422

25-
*/
26-
27-
2823
function getLength(arr, cb) {
29-
// getLength passes the length of the array into the callback.
24+
return cb(arr.length);
3025
}
26+
getLength(items,function(leng) {
27+
console.log(leng)
28+
});
3129

3230
function last(arr, cb) {
33-
// last passes the last item of the array into the callback.
31+
return cb(arr[arr.length -1]);
3432
}
33+
last(items,function(lst) {
34+
console.log(lst)
35+
});
3536

36-
function sumNums(x, y, cb) {
37+
function sumNums(x,y, cb) {
3738
// sumNums adds two numbers (x, y) and passes the result to the callback.
39+
return cb(x+y);
3840
}
41+
sumNums(2,4,function(num) {
42+
console.log(num)
43+
})
3944

4045
function multiplyNums(x, y, cb) {
4146
// multiplyNums multiplies two numbers and passes the result to the callback.
47+
return cb(x*y);
4248
}
49+
multiplyNums(2,9,function(num) {
50+
console.log(num)
51+
})
4352

4453
function contains(item, list, cb) {
4554
// contains checks if an item is present inside of the given array/list.
4655
// Pass true to the callback if it is, otherwise pass false.
56+
return cb(list.includes(item))
4757
}
4858

59+
contains(3,[4,5,3,2],function(num) {
60+
console.log(num)
61+
})
4962
/* STRETCH PROBLEM */
50-
51-
function removeDuplicates(array, cb) {
52-
// removeDuplicates removes all duplicate values from the given array.
53-
// Pass the duplicate free array to the callback function.
54-
// Do not mutate the original array.
55-
}
63+
// const items2 = ['Pencil','Pencil', 'Notebook', 'yo-yo', 'Gum'];
64+
// function removeDuplicates(arr) {
65+
// arr.reduce(ac, cb) => {
66+
// // removeDuplicates removes all duplicate values from the given array.
67+
// // Pass the duplicate free array to the callback function.
68+
// // Do not mutate the original array.
69+
// if (ac.indexOf(cb) === -1) {
70+
// return ac(cb);
71+
// // return cb(ac)
72+
// }
73+
// // return ac
74+
// }}
75+
// // console.log(items2);
76+
// removeDuplicates(items2,function(freeArray) {
77+
// console.log(freeArray)
78+
// })

‎assignments/closure.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3+
{
4+
let food = 'Meow Mix';
5+
console.log(food);
6+
};
7+
38

49

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

‎assignments/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script src="array-methods.js"></script>
1111
<script src="callbacks.js"></script>
1212
<script src="closure.js"></script>
13-
<script src="stretch-function-conversion.js"></script>
13+
<!-- <script src="stretch-function-conversion.js"></script> -->
1414
</head>
1515

1616
<body>

0 commit comments

Comments
 (0)