Created
August 6, 2014 21:11
-
-
Save noahadams/8483477ba8e84247f92d to your computer and use it in GitHub Desktop.
Javascript one-liner recursive map/reduce implementation
This file contains hidden or 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(arr, func) { return arr.length <= 1 ? [func(arr[0])] : [func(arr[0])].concat(map(arr.slice(1), func)) } | |
function reduce(arr, func, start) { return arr.length <= 1 ? func(arr[0], start) : func(arr[0], reduce(arr.slice(1), func, start)); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So memory hungry, but so fast to write.