diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ad007c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +package-lock.json +package.json \ No newline at end of file diff --git a/index.js b/index.js index 00a3d90..c6f264e 100644 --- a/index.js +++ b/index.js @@ -11,10 +11,25 @@ //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 + +let array1 = [11,3,5,8,4]; +console.log(array1); function map(array, iteratee){ + let newArr = []; + for(let i=0; i 5; } +filter(array1, iteratee2); //output: [11,8] //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find //create a function called `find`, it should take 2 parameters `theArray` and `fnc` //loop theArray and call the fnc for each thing in the array, @@ -35,36 +64,72 @@ function filter(array, iteratee){ //fnc will return true or false, if true return the item //after looping, return null function find(theArray, fnc){ + for(let i=0; i=0; i--){ + newArr.push(theArray[i]); + } + console.log(newArr); + return newArr; } +reverse(array1); //output: [4,8,5,3,11] + + //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){ - + let newArr = []; + for(let i=1; i theArray[i+1]){ + let temp = theArray[i]; + theArray[i] = theArray[i+1]; + theArray[i+1] = temp; + swapped = true; + } + } + if(swapped){ + sort(theArray); + } + else{ + console.log(theArray); + return theArray; + } } +sort(array1); //output: [3,4,5,8,11] + exports.map = map; exports.filter = filter; exports.find = find; diff --git a/packageTest.js b/packageTest.js new file mode 100644 index 0000000..17d1664 --- /dev/null +++ b/packageTest.js @@ -0,0 +1,6 @@ +let dash = require("aca-dash-selena-solis"); + +let array1 = [11,3,5,8,4]; + +let headOfArr = dash.head(array1); +console.log(headOfArr);