Skip to content

Instantly share code, notes, and snippets.

@mpj mpj/vanillahofs.js
Created Jan 13, 2020

Embed
What would you like to do?
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
You can’t perform that action at this time.