Skip to content

Commit e9664c4

Browse files
sofialevinsofialevin
authored andcommitted
Added comments back to callbacks.js to distinguish the different exercises.
1 parent 3d819ff commit e9664c4

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2525
*/
2626

2727
function getLength(arr, cb) {
28+
// getLength passes the length of the array into the callback.
2829
return cb(arr.length);
2930
}
3031

@@ -33,6 +34,7 @@ getLength(items, function(length) {
3334
})
3435

3536
function last(arr, cb) {
37+
// last passes the last item of the array into the callback.
3638
return cb(arr[arr.length - 1]);
3739
}
3840

@@ -41,6 +43,7 @@ last(items, function(lastItem) {
4143
})
4244

4345
function sumNums(x, y, cb) {
46+
// sumNums adds two numbers (x, y) and passes the result to the callback.
4447
return cb(x + y)
4548
}
4649

@@ -49,6 +52,7 @@ sumNums(3, 4, function(result) {
4952
})
5053

5154
function multiplyNums(x, y, cb) {
55+
// multiplyNums multiplies two numbers and passes the result to the callback.
5256
return cb(x * y);
5357
}
5458

@@ -57,12 +61,12 @@ multiplyNums(3, 5, function (result) {
5761
})
5862

5963
function contains(item, list, cb) {
60-
for (let i = 0; i < list.length; i++) {
61-
return cb(list[i] === item)
62-
}
64+
// contains checks if an item is present inside of the given array/list.
65+
// Pass true to the callback if it is, otherwise pass false.
66+
return cb(list.include(item))
6367
}
6468

65-
contains("Notebook", items, function(result) {
69+
contains('Gum', items, function(result) {
6670
console.log(result);
6771
})
6872

0 commit comments

Comments
 (0)