@@ -36,26 +36,45 @@ getLength(items, function(length){
3636
3737 ///////////////////////////////// last passes the last item of the array into the callback.
3838function last ( arr , cb ) {
39-
4039 return cb ( arr [ `${ arr . length - 1 } ` ] ) ;
4140}
4241last ( items , function ( lastItemOfArray ) {
4342 console . log ( lastItemOfArray ) ;
4443} ) ;
4544
46- ////////////////////////////////// sumNums adds two numbers (x, y) and passes the result to the callback.
45+ ////////////////////// sumNums adds two numbers (x, y) and passes the result to the callback.
4746function sumNums ( x , y , cb ) {
48-
47+ const total = x + y ;
48+ return cb ( total ) ;
4949}
5050
51+ sumNums ( 2 , 5 , function ( result ) {
52+ console . log ( result ) ;
53+ } ) ;
54+
55+ /////////////////////// multiplyNums multiplies two numbers and passes the result to the callback.
5156function multiplyNums ( x , y , cb ) {
52- // multiplyNums multiplies two numbers and passes the result to the callback.
57+ const total = x * y ;
58+ return cb ( total ) ;
59+
5360}
5461
55- function contains ( item , list , cb ) {
56- // contains checks if an item is present inside of the given array/list.
57- // Pass true to the callback if it is, otherwise pass false.
62+ multiplyNums ( 5 , 5 , function ( result ) {
63+ console . log ( result ) ;
64+ } ) ;
65+
66+ /////////////////// contains checks if an item is present inside of the given array/list.
67+ /////////////////// Pass true to the callback if it is, otherwise pass false.
68+ function contains ( lookingForItem , arr , cb ) {
69+ arr . forEach ( function findIt ( listItem ) {
70+ if ( listItem == lookingForItem ) {
71+ return cb ( true ) ;
72+ } else { return cb ( false ) ; }
73+ } ) ;
5874}
75+ contains ( "Pencil" , items , function ( result ) {
76+ console . log ( result ) ;
77+ } ) ;
5978
6079/* STRETCH PROBLEM */
6180
0 commit comments