@@ -7,36 +7,36 @@ const displayCallback = (arr) => {
77
88function firstItem ( arr , cb ) {
99 // firstItem passes the first item of the given array to the callback function.
10- return cb ( arr [ 0 ] ) ;
10+ cb ( arr [ 0 ] ) ;
1111}
1212
1313firstItem ( items , displayCallback ) ;
1414
1515function getLength ( arr , cb ) {
1616 // getLength passes the length of the array into the callback.
17- return cb ( arr . length ) ;
17+ cb ( arr . length ) ;
1818}
1919
2020getLength ( items , displayCallback ) ;
2121
2222
2323function last ( arr , cb ) {
2424 // last passes the last item of the array into the callback.
25- return cb ( arr [ arr . length - 1 ] ) ;
25+ cb ( arr [ arr . length - 1 ] ) ;
2626}
2727
2828last ( items , displayCallback ) ;
2929
3030function sumNums ( x , y , cb ) {
3131 // sumNums adds two numbers (x, y) and passes the result to the callback.
32- return cb ( x + y ) ;
32+ cb ( x + y ) ;
3333}
3434
3535sumNums ( 3 , 4 , displayCallback ) ;
3636
3737function multiplyNums ( x , y , cb ) {
3838 // multiplyNums multiplies two numbers and passes the result to the callback.
39- return cb ( x * y ) ;
39+ cb ( x * y ) ;
4040}
4141
4242multiplyNums ( 3 , 4 , displayCallback ) ;
@@ -45,9 +45,9 @@ function contains(item, list, cb) {
4545 // contains checks if an item is present inside of the given array/list.
4646 // Pass true to the callback if it is, otherwise pass false.
4747 if ( list . includes ( item ) ) {
48- return cb ( true ) ;
48+ cb ( true ) ;
4949 } else {
50- return cb ( false ) ;
50+ cb ( false ) ;
5151 }
5252}
5353
@@ -59,16 +59,16 @@ contains("stick", items, displayCallback);
5959function removeDuplicates ( array , cb ) {
6060 let newArr = [ ] ;
6161 array . forEach ( ( element ) => {
62- if ( newArr . includes ( element ) ) {
63- console . log ( `Duplicate element: ${ element } skipped` ) ;
64- } else {
62+ if ( ! newArr . includes ( element ) ) {
6563 newArr . push ( element ) ;
64+ } else {
65+ console . log ( `Duplicate element: ${ element } skipped` ) ;
6666 }
6767 } ) ;
6868 // removeDuplicates removes all duplicate values from the given array.
6969 // Pass the duplicate free array to the callback function.
7070 // Do not mutate the original array.
71- return cb ( array ) ;
71+ cb ( newArr ) ;
7272}
7373
7474removeDuplicates ( items , displayCallback ) ;
0 commit comments