Skip to content

Commit 505ffa7

Browse files
committed
changed some things
1 parent 0f77f59 commit 505ffa7

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,54 @@
22

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

5-
65

7-
//Given this problem:
8-
9-
// function firstItem(arr, cb) {
10-
// // firstItem passes the first item of the given array to the callback function.
11-
// }
126

13-
// Potential Solution:
14-
function firstItem(arr, cb) {
15-
return cb(arr[0]);
16-
}
7+
//Given this problem:
8+
9+
// function firstItem(arr, cb) {
10+
// // firstItem passes the first item of the given array to the callback function.
11+
// }
12+
13+
// Potential Solution:
14+
function firstItem(arr, cb) {
15+
return cb(arr[0]);
16+
}
1717

18-
firstItem(items, function(first) {
19-
console.log(first)
20-
});
18+
firstItem(items, function (first) {
19+
console.log(first)
20+
});
2121

2222
function getLength(arr, cb) {
2323
// getLength passes the length of the array into the callback.
2424
return cb(arr.length);
2525
}
26-
getLength(items,function(length) {
26+
getLength(items, function (length) {
2727
console.log(length);
2828
});
2929

3030
function last(arr, cb) {
3131
// last passes the last item of the array into the callback.
32-
return cb(arr[arr.length-1])
32+
return cb(arr[arr.length - 1])
3333
}
34-
last(items, function(lastItem) {
34+
35+
last(items, function (lastItem) {
3536
console.log(lastItem);
3637
});
3738

3839
function sumNums(x, y, cb) {
3940
// sumNums adds two numbers (x, y) and passes the result to the callback.
40-
return cb(x+y);
41+
return cb(x + y);
4142
}
42-
sumNums(2,3, function(sumOfNums) {
43+
sumNums(2, 3, function (sumOfNums) {
4344
console.log(sumOfNums);
4445
});
4546

4647

4748
function multiplyNums(x, y, cb) {
4849
// multiplyNums multiplies two numbers and passes the result to the callback.
49-
return cb(x*y);
50+
return cb(x * y);
5051
}
51-
multiplyNums(2,3, function(product) {
52+
multiplyNums(2, 3, function (product) {
5253
console.log(product);
5354
})
5455

@@ -62,16 +63,18 @@ function contains(item, list, cb) {
6263
}
6364
}
6465

65-
contains('Notebook', items, function(matched) {
66+
contains('Notebook', items, function (matched) {
6667
console.log(matched);
6768
})
6869

6970
/* STRETCH PROBLEM */
7071

72+
const stretchItems = ['hello', 'goodbye', 'hola', 'adios', 'hello', 'hello', 'shalom', 'gutentag', 'shalom'];
73+
7174
function removeDuplicates(array, cb) {
7275
// removeDuplicates removes all duplicate values from the given array.
7376
// Pass the duplicate free array to the callback function.
7477
// Do not mutate the original array.
75-
7678

7779
}
80+

‎assignments/closure.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
// Write a simple closure of your own creation. Keep it simple!
33
let favCandy = "jelly beans";
44
function trickOrTreat() {
5-
return "Trick or treat can I have some "+favCandy+"?";
5+
return `Trick or treat can I have some ${favCandy}?`;
66
}
77

8+
let otherCandy = "candy corn";
9+
function sorry() {
10+
favCandy = "chocolate bars";
11+
return `Sorry, we don't have any ${favCandy}!`;
12+
13+
}
814

915
console.log(trickOrTreat());
16+
console.log(sorry(otherCandy));
1017

1118
// ==== Challenge 2: Create a counter function ====
19+
1220
const counter = () => {
1321
// Return a function that when invoked increments and returns a counter variable.
14-
let count = 0;
22+
let count = 0;
1523
return() => ++count;
1624

1725
};

0 commit comments

Comments
 (0)