Created
January 13, 2020 16:49
-
-
Save mpj/cc4005e34f4bffea73d785b8918709ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [ 2, 4, 8, 9 ] | |
const addTwo = number => number + 1 | |
const isMoreThan5 = number => number > 5 | |
const result = | |
//numbers.filter(isMoreThan5) | |
filterArray(isMoreThan5, numbers) | |
//mapArray(addTwo, numbers | |
result | |
function filterArray(predicate, array) { | |
let filteredArray = [] | |
for(let i = 0; i < array.length; i++) { | |
const currentItem = array[i] | |
if(predicate(currentItem)) { | |
filteredArray.push(currentItem) | |
} | |
} | |
return filteredArray | |
} | |
function mapArray(transform, array) { | |
let transformedArray = [] | |
for(let i = 0; i < array.length; i++) { | |
transformedArray.push(transform(array[i])) | |
} | |
return transformedArray | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment