@@ -26,41 +26,41 @@ const items2 = ['Pencil', 'Notebook', 'yo-yo', 'Gum', 'Gum', 'yarn', 'yo-yo' ];
2626
2727*/
2828console . log ( `********* callback.js challenges *********` )
29- function getLength ( arr , cb ) {
29+ const getLength = ( arr , cb ) => {
3030 // getLength passes the length of the array into the callback.
3131 return cb ( arr . length )
3232}
3333
34- getLength ( items , function ( theLength ) {
34+ getLength ( items , ( theLength ) => {
3535 console . log ( "getLength function: " , theLength )
3636} )
3737
38- function last ( arr , cb ) {
38+ const last = ( arr , cb ) => {
3939 // last passes the last item of the array into the callback.
4040 return cb ( arr . length - 1 )
4141}
4242
43- last ( items , function ( lastItem ) {
43+ last ( items , ( lastItem ) => {
4444 console . log ( `lastItem function: ${ lastItem } ` ) ;
4545 console . dir ( lastItem ) ;
4646} )
4747
4848
49- function sumNums ( x , y , cb ) {
49+ const sumNums = ( x , y , cb ) => {
5050 // sumNums adds two numbers (x, y) and passes the result to the callback.
5151 return cb ( x + y ) ;
5252}
5353
54- sumNums ( 3 , 4 , function ( sum ) {
54+ sumNums ( 3 , 4 , ( sum ) => {
5555 console . log ( 'the sum is: ' , sum )
5656} )
5757
58- function multiplyNums ( x , y , cb ) {
58+ const multiplyNums = ( x , y , cb ) => {
5959 return cb ( x * y )
6060 // multiplyNums multiplies two numbers and passes the result to the callback.
6161}
6262
63- multiplyNums ( 3 , 4 , function ( mult ) {
63+ multiplyNums ( 3 , 4 , ( mult ) => {
6464 console . log ( "the multiplied value is: " , mult )
6565} )
6666
@@ -72,7 +72,7 @@ multiplyNums(3, 4, function(mult){
7272
7373// multiplyNums(2, 4, multiplying)
7474
75- function contains ( item , list , cb ) {
75+ const contains = ( item , list , cb ) => {
7676 // contains checks if an item is present inside of the given array/list.
7777 // Pass true to the callback if it is, otherwise pass false.
7878 return cb ( item , list )
@@ -81,7 +81,7 @@ function contains(item, list, cb) {
8181}
8282
8383// researched "includes" method from MDN
84- function inventory ( item , list ) {
84+ const inventory = ( item , list ) => {
8585 return list . includes ( item )
8686}
8787
@@ -100,14 +100,14 @@ function inventory(item, list){
100100
101101/* STRETCH PROBLEM */
102102
103- function removeDuplicates ( array , cb ) {
103+ const removeDuplicates = ( array , cb ) => {
104104 // removeDuplicates removes all duplicate values from the given array.
105105 // Pass the duplicate free array to the callback function.
106106 // Do not mutate the original array.
107107 return cb ( array )
108108}
109109
110- function removeThem ( array ) {
110+ const removeThem = ( array ) => {
111111 return array . filter ( function ( item , index ) {
112112 return array . indexOf ( item ) >= index ;
113113 } ) ;
@@ -118,4 +118,4 @@ function removeThem(array){
118118
119119// created duplicate items array to check if it worked
120120 removeDuplicates ( items2 , removeThem )
121- console . log ( "Removed duplicates from array of items2:" , removeDuplicates ( items2 , removeThem ) )
121+ console . log ( "Removed duplicates from array of items2:" , removeDuplicates ( items2 , removeThem ) )
0 commit comments