Skip to content

Commit 90cc0f0

Browse files
sofialevinsofialevin
authored andcommitted
Completed callbacks.js
1 parent bc4a039 commit 90cc0f0

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

assignments/callbacks.js

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

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

31+
getLength(items, function(length) {
32+
console.log(length);
33+
})
34+
3235
function last(arr, cb) {
33-
// last passes the last item of the array into the callback.
36+
return cb(arr[arr.length - 1]);
3437
}
3538

39+
last(items, function(lastItem) {
40+
console.log(lastItem)
41+
})
42+
3643
function sumNums(x, y, cb) {
37-
// sumNums adds two numbers (x, y) and passes the result to the callback.
44+
return cb(x + y)
3845
}
3946

47+
sumNums(3, 4, function(result) {
48+
console.log(result)
49+
})
50+
4051
function multiplyNums(x, y, cb) {
41-
// multiplyNums multiplies two numbers and passes the result to the callback.
52+
return cb(x * y);
4253
}
4354

55+
multiplyNums(3, 5, function (result) {
56+
console.log(result);
57+
})
58+
4459
function contains(item, list, cb) {
45-
// contains checks if an item is present inside of the given array/list.
46-
// Pass true to the callback if it is, otherwise pass false.
60+
for (let i = 0; i < list.length; i++) {
61+
return cb(list[i] === item)
62+
}
4763
}
4864

65+
contains("Notebook", items, function(result) {
66+
console.log(result);
67+
})
68+
4969
/* STRETCH PROBLEM */
5070

5171
function removeDuplicates(array, cb) {

0 commit comments

Comments
 (0)