diff --git a/index.js b/index.js index a32d484..ddf3d5d 100644 --- a/index.js +++ b/index.js @@ -11,9 +11,19 @@ //iteratee is a function that must return something, capture whatever it returns in a variable //add the returned value from iteratee tp myNewArray //after looping, return myNewArray -function map(array, iteratee){ - -} +function map(array, fnc){ + const myNewArray=[]; + for (let i=0; i< array.length; i++){ + const newNumber = fnc (array[i]); + myNewArray.push(newNumber) + } + return(myNewArray) + } + const arr= [1,2,3,4]; + const fnc=(x)=>{ + if (x===1||3) return(x) + }; +map(arr,fnc) //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter //create a function called `filter`, it should take 2 parameters `array` and `iteratee` @@ -24,8 +34,17 @@ function map(array, iteratee){ // passing in the item from the current loop //iteratee will return true or false, if true add the item to myNewArray else do not //after looping, return myNewArray -function filter(array, iteratee){ - +function filter(array, fnc){ + myNewArray=[], + for (i=0,i= 0; i--){ +newArray.push(theArray [i]); } +return newArray; +} + //create a new array //loop theArray //add the item from each loop to the new array except the first item //return the new array function tail(theArray){ - + const newArray=[]; + for (let i=1; i < theArray.length; i++){ + newArray.push(theArray[i]); + } + return newArray; } + //implement the most basic sorting algorithm there is //assume the array will always have numbers //use a while loop to constantly loop theArray until it is sorted