@@ -24,28 +24,48 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424
2525*/
2626
27-
2827function getLength ( arr , cb ) {
29- // getLength passes the length of the array into the callback.
28+ return cb ( arr . length ) ;
3029}
3130
31+ getLength ( items , function ( length ) {
32+ console . log ( length ) ;
33+ } )
34+
3235function last ( arr , cb ) {
33- // last passes the last item of the array into the callback.
36+ return cb ( arr [ arr . length - 1 ] ) ;
3437}
3538
39+ last ( items , function ( lastItem ) {
40+ console . log ( lastItem )
41+ } )
42+
3643function sumNums ( x , y , cb ) {
37- // sumNums adds two numbers (x, y) and passes the result to the callback.
44+ return cb ( x + y )
3845}
3946
47+ sumNums ( 3 , 4 , function ( result ) {
48+ console . log ( result )
49+ } )
50+
4051function multiplyNums ( x , y , cb ) {
41- // multiplyNums multiplies two numbers and passes the result to the callback.
52+ return cb ( x * y ) ;
4253}
4354
55+ multiplyNums ( 3 , 5 , function ( result ) {
56+ console . log ( result ) ;
57+ } )
58+
4459function contains ( item , list , cb ) {
45- // contains checks if an item is present inside of the given array/list.
46- // Pass true to the callback if it is, otherwise pass false.
60+ for ( let i = 0 ; i < list . length ; i ++ ) {
61+ return cb ( list [ i ] === item )
62+ }
4763}
4864
65+ contains ( "Notebook" , items , function ( result ) {
66+ console . log ( result ) ;
67+ } )
68+
4969/* STRETCH PROBLEM */
5070
5171function removeDuplicates ( array , cb ) {
0 commit comments