Last active
December 20, 2017 21:42
-
-
Save yourpalsonja/6c88c9157e90490f73da236a113f7b7c 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
var boringArray = [1,2,3,4]; | |
const rReduce = (arr, func, acc) => { | |
acc ? acc : arr[0]; | |
if(arr.length === 0) { | |
return acc; | |
} | |
return rReduce(arr.slice(1), func, func(acc, arr[0])) | |
}; | |
const doubler = (i) => { | |
return i * 2; | |
} | |
const rMap = (arr, func) => { | |
const accumulate = (acc, e) => { | |
acc.push(func(e)); | |
return acc; | |
}; | |
return rReduce(arr, accumulate, []) | |
}; | |
console.log(rMap(boringArray, doubler)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment