Skip to content

Commit 8b1ecb6

Browse files
committed
callbacks
1 parent 1146fc5 commit 8b1ecb6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

assignments/callbacks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
22

33
function firstItem(arr, cb) {
44
// firstItem passes the first item of the given array to the callback function.
5+
cb(arr[0]);
56
}
67

78
function getLength(arr, cb) {
89
// getLength passes the length of the array into the callback.
10+
cb(arr.length);
911
}
1012

1113
function last(arr, cb) {
1214
// last passes the last item of the array into the callback.
15+
cb(arr[arr.length-1]);
1316
}
1417

1518
function sumNums(x, y, cb) {
1619
// sumNums adds two numbers (x, y) and passes the result to the callback.
20+
cb(x + y);
1721
}
1822

1923
function multiplyNums(x, y, cb) {
2024
// multiplyNums multiplies two numbers and passes the result to the callback.
25+
cb(x * y);
2126
}
2227

2328
function contains(item, list, cb) {
2429
// contains checks if an item is present inside of the given array/list.
2530
// Pass true to the callback if it is, otherwise pass false.
31+
cb(list.includes(item));
2632
}
2733

2834
/* STRETCH PROBLEM */
@@ -31,4 +37,5 @@ function removeDuplicates(array, cb) {
3137
// removeDuplicates removes all duplicate values from the given array.
3238
// Pass the duplicate free array to the callback function.
3339
// Do not mutate the original array.
40+
3441
}

0 commit comments

Comments
 (0)