Created
February 12, 2020 18:48
-
-
Save JakeTheCorn/ef2691f73e945e1eba0a5d02a27c2a22 to your computer and use it in GitHub Desktop.
todo: write tests. little recursive function fun.
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
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