@@ -8,8 +8,16 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
88
99 function firstItem(arr, cb) {
1010 // firstItem passes the first item of the given array to the callback function.
11- }
11+ }*/
12+ //My solution:
13+ // function firstItem(arr,cb){
14+ // return cb(arr[0]);
15+ // };
16+
17+ // firstItem(items,function(first){
18+ // console.log(first); });
1219
20+ /*
1321 // Potential Solution:
1422
1523 // Higher order function using "cb" as the call back
@@ -24,18 +32,32 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2432
2533*/
2634
35+ //My Solution:
36+ // function getLength(arr, cb) {
37+ // // getLength passes the length of the array into the callback.
38+ // return cb(arr.length);
39+ // }
40+ // getLength(items,function(length){
41+ // console.log(length);
42+ // });
2743
28- function getLength ( arr , cb ) {
29- // getLength passes the length of the array into the callback.
30- }
44+ // function last(arr, cb) {
45+ // // last passes the last item of the array into the callback.
46+ // return cb(arr.pop())
47+ // }
48+ // last(items,function(final){
49+ // console.log(final);
50+ // });
3151
32- function last ( arr , cb ) {
33- // last passes the last item of the array into the callback.
34- }
3552
36- function sumNums ( x , y , cb ) {
37- // sumNums adds two numbers (x, y) and passes the result to the callback.
38- }
53+ // function sumNums(x, y, cb) {
54+ // // sumNums adds two numbers (x, y) and passes the result to the callback.
55+ // return cb(x+y);
56+ // }
57+ // sumNums(2,3, function(sum){
58+ // console.log(sum);
59+ // });
60+
3961
4062function multiplyNums ( x , y , cb ) {
4163 // multiplyNums multiplies two numbers and passes the result to the callback.
0 commit comments