Skip to content

Commit 0951e9e

Browse files
committed
callback v1
1 parent 770541a commit 0951e9e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

assignments/callbacks.js

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

27-
27+
/////////////////////////////////// getLength passes the length of the array into the callback.
2828
function getLength(arr, cb) {
29-
// getLength passes the length of the array into the callback.
29+
return cb(arr.length);
3030
}
3131

32+
getLength(items, function(length){
33+
console.log(length);
34+
});
35+
36+
37+
///////////////////////////////// last passes the last item of the array into the callback.
3238
function last(arr, cb) {
33-
// last passes the last item of the array into the callback.
39+
40+
return cb(arr[`${arr.length - 1}`]);
3441
}
42+
last(items,function(lastItemOfArray){
43+
console.log(lastItemOfArray);
44+
});
3545

46+
////////////////////////////////// sumNums adds two numbers (x, y) and passes the result to the callback.
3647
function sumNums(x, y, cb) {
37-
// sumNums adds two numbers (x, y) and passes the result to the callback.
48+
3849
}
3950

4051
function multiplyNums(x, y, cb) {

0 commit comments

Comments
 (0)