Skip to content
Open
Show file tree
Hide file tree
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
64 changes: 50 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
//`iteratee` must be a function that takes one parameter and returns a bool
//The point of the javascript map function is to take an array and return different array with the exact same number of items in it
//The items will be whatever the function `iteratee` creates
//in the map function create a new empty array and store in a variable named whatever you want (myNewArray)
//loop array and extract the single item from the array per loop and store it in a variable
//on each loop call iteratee() passing in the item from the current loop into the call to iteratee()
//-in the map function create a new empty array and store in a variable named whatever you want (myNewArray)
//-loop array and extract the single item from the array per loop and store it in a variable
//-on each loop call iteratee() passing in the item from the current loop into the call to iteratee()
//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){

myNewArray = [];
for(let i=0; i < array.lenght; i++){
let arrayElement = array[i];
let returnedValue = iteratee(arrayElement);
myNewArray.push(returnedValue);
}
return myNewArray;
}



//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`
//`array` must be an array
Expand All @@ -25,7 +33,13 @@ function map(array, iteratee){
//iteratee will return true or false, if true add the item to myNewArray else do not
//after looping, return myNewArray
function filter(array, iteratee){

let myNewArray = [];
for(let i = 0; i < array.length; i++){
let arrayElement = array[i];
if(iteratee(arrayElement) === true){
myNewArray.push(arrayElement)
};
} return myNewArray;
}

//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
Expand All @@ -35,34 +49,45 @@ 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 < array.lenght; i++){
if (fnc(theArray[i]) === true){
return theArray[i];
}
} return null;
}


//return the last item in 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){

}
let reversedArray = [];
for(let i= theArray.length-1; i > -1; i--){
reversedArray.unshift(theArray[i])
} return reversedArray
};

//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 newArray = [];
for(let i =1; i < theArray.length;i++){
newArray.push(theArray[i]);
} return newArray

}

//implement the most basic sorting algorithm there is
Expand All @@ -76,8 +101,19 @@ function tail(theArray){
//after each for loop check the variable, if true, continue the while loop
//if false return theArray
function sort(theArray){

}
//sorting function to sort the numbers from least to greatest;
function sortArray(a,b){
if(a >b){
return 1;
} else if(b>a){
return -1;
} else {
return 0;
}
} return theArray.sort(sortArray);


};

exports.map = map;
exports.filter = filter;
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "andrew-dash",
"version": "1.0.0",
"description": "useful functions",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AndrewSommer89/aca-dash.git"
},
"author": "Andrew Sommer",
"license": "ISC",
"bugs": {
"url": "https://github.com/AndrewSommer89/aca-dash/issues"
},
"homepage": "https://github.com/AndrewSommer89/aca-dash#readme"
}