Skip to content

Commit ef67da1

Browse files
committed
ft(create a callback)
create a callback that returns the the length of an array
1 parent fcb2b28 commit ef67da1

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎assignments/callbacks.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Create a higher order function and invoke the callback function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.
1+
// Create a higher order function and invoke the callback function to test your work.
2+
// You have been provided an example of a problem and a solution to see how this works with our items array.
3+
// Study both the problem and the solution to figure out the rest of the problems.
24

35
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
46

@@ -24,11 +26,17 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2426
2527
*/
2628

29+
// call back function
30+
const callback = val => console.log(val);
2731

2832
function getLength(arr, cb) {
2933
// getLength passes the length of the array into the callback.
34+
let arrLength = arr.length;
35+
return cb(arrLength);
3036
}
3137

38+
getLength(items, callback);
39+
3240
function last(arr, cb) {
3341
// last passes the last item of the array into the callback.
3442
}

0 commit comments

Comments
 (0)