Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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<array.length; i++){
const num = fnc(array[i]);
if (num===1||num===3){
myNewArray.push(num);
}
}
return (myNewArray)
}

}

//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
Expand All @@ -34,37 +53,55 @@ function filter(array, iteratee){
// passing in the item from the current loop
//fnc will return true or false, if true return the item
//after looping, return null
function find(theArray, fnc){

}
function find(theArray, fnc){
for (let i=0; i < theArray.length; i++){
if (fnc(theArray[i])){
return theArray[i];
}
}
}



//return the last item in theArray
function findLast(theArray){

function findLast(theArray){
return theArray[theArray.length-1];
}

//return the first element of the array
function head(theArray){

return theArray[0];
}

//create a new array
//loop theArray in reverse order
//add the item from each loop to the new array
//return the new array
function reverse(theArray){

function reverse(theArray){
const newArray = [];
for (let i= theArray.length -1; 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
Expand Down