22
33const items = [ 'Pencil' , 'Notebook' , 'yo-yo' , 'Gum' ] ;
44
5-
65
7- //Given this problem:
8-
9- // function firstItem(arr, cb) {
10- // // firstItem passes the first item of the given array to the callback function.
11- // }
126
13- // Potential Solution:
14- function firstItem ( arr , cb ) {
15- return cb ( arr [ 0 ] ) ;
16- }
7+ //Given this problem:
8+
9+ // function firstItem(arr, cb) {
10+ // // firstItem passes the first item of the given array to the callback function.
11+ // }
12+
13+ // Potential Solution:
14+ function firstItem ( arr , cb ) {
15+ return cb ( arr [ 0 ] ) ;
16+ }
1717
18- firstItem ( items , function ( first ) {
19- console . log ( first )
20- } ) ;
18+ firstItem ( items , function ( first ) {
19+ console . log ( first )
20+ } ) ;
2121
2222function getLength ( arr , cb ) {
2323 // getLength passes the length of the array into the callback.
2424 return cb ( arr . length ) ;
2525}
26- getLength ( items , function ( length ) {
26+ getLength ( items , function ( length ) {
2727 console . log ( length ) ;
2828} ) ;
2929
3030function last ( arr , cb ) {
3131 // last passes the last item of the array into the callback.
32- return cb ( arr [ arr . length - 1 ] )
32+ return cb ( arr [ arr . length - 1 ] )
3333}
34- last ( items , function ( lastItem ) {
34+
35+ last ( items , function ( lastItem ) {
3536 console . log ( lastItem ) ;
3637} ) ;
3738
3839function sumNums ( x , y , cb ) {
3940 // sumNums adds two numbers (x, y) and passes the result to the callback.
40- return cb ( x + y ) ;
41+ return cb ( x + y ) ;
4142}
42- sumNums ( 2 , 3 , function ( sumOfNums ) {
43+ sumNums ( 2 , 3 , function ( sumOfNums ) {
4344 console . log ( sumOfNums ) ;
4445} ) ;
4546
4647
4748function multiplyNums ( x , y , cb ) {
4849 // multiplyNums multiplies two numbers and passes the result to the callback.
49- return cb ( x * y ) ;
50+ return cb ( x * y ) ;
5051}
51- multiplyNums ( 2 , 3 , function ( product ) {
52+ multiplyNums ( 2 , 3 , function ( product ) {
5253 console . log ( product ) ;
5354} )
5455
@@ -62,16 +63,18 @@ function contains(item, list, cb) {
6263 }
6364}
6465
65- contains ( 'Notebook' , items , function ( matched ) {
66+ contains ( 'Notebook' , items , function ( matched ) {
6667 console . log ( matched ) ;
6768} )
6869
6970/* STRETCH PROBLEM */
7071
72+ const stretchItems = [ 'hello' , 'goodbye' , 'hola' , 'adios' , 'hello' , 'hello' , 'shalom' , 'gutentag' , 'shalom' ] ;
73+
7174function removeDuplicates ( array , cb ) {
7275 // removeDuplicates removes all duplicate values from the given array.
7376 // Pass the duplicate free array to the callback function.
7477 // Do not mutate the original array.
75-
7678
7779}
80+
0 commit comments