Skip to content

Commit 86de91e

Browse files
committed
done callbacks
1 parent aae5f2d commit 86de91e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

assignments/callbacks.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,41 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2020
});
2121
2222
*/
23-
23+
//console.logs whatever it is given
24+
function logger(logMe){
25+
console.log(logMe);
26+
}
2427

2528
function getLength(arr, cb) {
2629
// getLength passes the length of the array into the callback.
30+
cb(arr.length);
2731
}
32+
//getLength(items, logger);
2833

2934
function last(arr, cb) {
3035
// last passes the last item of the array into the callback.
36+
cb(arr[arr.length-1]);
3137
}
38+
//last(items, logger);
3239

3340
function sumNums(x, y, cb) {
3441
// sumNums adds two numbers (x, y) and passes the result to the callback.
42+
cb(x+y);
3543
}
44+
//sumNums(3, 2, logger);
3645

3746
function multiplyNums(x, y, cb) {
3847
// multiplyNums multiplies two numbers and passes the result to the callback.
48+
cb(x*y);
3949
}
50+
//multiplyNums(3, 5, logger);
4051

4152
function contains(item, list, cb) {
4253
// contains checks if an item is present inside of the given array/list.
4354
// Pass true to the callback if it is, otherwise pass false.
55+
cb(list.includes(item));
4456
}
57+
//contains("Gum", items, logger);
4558

4659
/* STRETCH PROBLEM */
4760

assignments/closure.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ const counter = () => {
1515
let count =0;
1616

1717
return function () {
18-
console.log(count);
18+
//console.log(count);
1919
return count++;
2020
}
2121
};
2222
const counterOne = counter();
23-
counterOne();
24-
counterOne();
25-
counterOne();
26-
counterOne();
23+
//counterOne();
24+
//counterOne();
25+
//counterOne();
26+
//counterOne();
27+
2728
// Example usage: const newCounter = counter();
2829
// newCounter(); // 1
2930
// newCounter(); // 2

0 commit comments

Comments
 (0)