Skip to content

Instantly share code, notes, and snippets.

@JakeTheCorn
Created February 12, 2020 18:48
Show Gist options
  • Save JakeTheCorn/ef2691f73e945e1eba0a5d02a27c2a22 to your computer and use it in GitHub Desktop.
Save JakeTheCorn/ef2691f73e945e1eba0a5d02a27c2a22 to your computer and use it in GitHub Desktop.
todo: write tests. little recursive function fun.
function map(fn) {
let newArr = []
let idx = 0
return function mapper(arr) {
if (arr.length === idx) {
return newArr
}
const item = fn(arr[idx])
newArr.push(item)
idx++
return mapper(arr)
}
}
// todo: write tests
var timesTwo = a => a * 2
var mapTimesTwo = map(timesTwo)
mapTimesTwo([1, 2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment