Skip to content

Commit d05f670

Browse files
callbacks.js Done
1 parent ce46022 commit d05f670

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,34 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424

2525
function getLength(arr, cb) {
2626
// getLength passes the length of the array into the callback.
27+
return cb(arr.length);
2728
}
2829

2930
function last(arr, cb) {
3031
// last passes the last item of the array into the callback.
32+
return cb(arr[arr.length-1]);
3133
}
3234

3335
function sumNums(x, y, cb) {
3436
// sumNums adds two numbers (x, y) and passes the result to the callback.
37+
return cb(x + y);
3538
}
3639

3740
function multiplyNums(x, y, cb) {
3841
// multiplyNums multiplies two numbers and passes the result to the callback.
42+
return cb(X * y);
3943
}
4044

4145
function contains(item, list, cb) {
4246
// contains checks if an item is present inside of the given array/list.
4347
// Pass true to the callback if it is, otherwise pass false.
48+
for(let i = 0; i < list.length; i++) {
49+
if(list[i] === item) {
50+
return cb(true);
51+
} else {
52+
return cb(false);
53+
}
54+
}
4455
}
4556

4657
/* STRETCH PROBLEM */
@@ -49,4 +60,6 @@ function removeDuplicates(array, cb) {
4960
// removeDuplicates removes all duplicate values from the given array.
5061
// Pass the duplicate free array to the callback function.
5162
// Do not mutate the original array.
63+
const set1 = new Set(array);
64+
return cb(set1);
5265
}

0 commit comments

Comments
 (0)