@@ -2,31 +2,64 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
22
33function firstItem ( arr , cb ) {
44 // firstItem passes the first item of the given array to the callback function.
5+ return cb ( arr [ 0 ] ) ;
56}
67
78function getLength ( arr , cb ) {
89 // getLength passes the length of the array into the callback.
10+ return cb ( arr . length ) ;
911}
1012
1113function last ( arr , cb ) {
1214 // last passes the last item of the array into the callback.
15+ return cb ( arr [ arr . length - 1 ] ) ;
1316}
1417
1518function sumNums ( x , y , cb ) {
1619 // sumNums adds two numbers (x, y) and passes the result to the callback.
20+ return cb ( x + y ) ;
1721}
1822
1923function multiplyNums ( x , y , cb ) {
2024 // multiplyNums multiplies two numbers and passes the result to the callback.
25+ return cb ( x * y ) ;
2126}
2227
28+ // testing
29+ // -- 1 --
30+ firstItem ( items , ( item ) => {
31+ console . log ( item )
32+ } ) ; // --> Pencil
33+
34+ // -- 2 --
35+ getLength ( items , ( length ) => {
36+ console . log ( length ) ;
37+ } ) ; // --> 4
38+
39+ // -- 3 --
40+ last ( items , ( item ) => {
41+ console . log ( item ) ;
42+ } ) ; // --> Gum
43+
44+ // -- 4 --
45+ sumNums ( 4 , 6 , ( result ) => {
46+ console . log ( result ) ;
47+ } ) ; // --> 10
48+
49+ // -- 5 --
50+ multiplyNums ( 4 , 6 , ( result ) => {
51+ console . log ( result ) ;
52+ } ) ; // --> 24
53+
54+
55+
56+ /* STRETCH PROBLEM */
57+
2358function contains ( item , list , cb ) {
2459 // contains checks if an item is present inside of the given array/list.
2560 // Pass true to the callback if it is, otherwise pass false.
2661}
2762
28- /* STRETCH PROBLEM */
29-
3063function removeDuplicates ( array , cb ) {
3164 // removeDuplicates removes all duplicate values from the given array.
3265 // Pass the duplicate free array to the callback function.
0 commit comments