@@ -2,33 +2,57 @@ 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
2328function contains ( item , list , cb ) {
2429 // contains checks if an item is present inside of the given array/list.
2530 // Pass true to the callback if it is, otherwise pass false.
31+ if ( list . includes ( item ) ) {
32+ return cb ( true ) ;
33+ } else {
34+ return cb ( false ) ;
35+ }
2636}
2737
2838/* STRETCH PROBLEM */
29-
30- function removeDuplicates ( array , cb ) {
39+ // const myarray = ['hey','hey','yo'];
40+ // let newArr = [];
41+ function removeDuplicates ( myarray , cb ) {
3142 // removeDuplicates removes all duplicate values from the given array.
3243 // Pass the duplicate free array to the callback function.
3344 // Do not mutate the original array.
45+
46+ //creates copy of array
47+ // newArr = myarray.slice(0);
48+ // console.log(newArr);
49+
50+ //reduce
51+
52+
53+
3454}
55+
56+ // console.log(newArr);
57+ // removeDuplicates(myarray);
58+
0 commit comments