Created
April 4, 2012 14:49
-
-
Save sergi/2302088 to your computer and use it in GitHub Desktop.
JavaScript reduce implementation
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 __reduce= function (func, list, initial) { | |
if (initial != null) { | |
var value = initial; | |
var idx = 0; | |
} else if (list) { | |
var value = list[0]; | |
var idx = 1; | |
} else { | |
return null; | |
} | |
for (; idx < list.length; idx++) { | |
value = func(value, list[idx]); | |
} | |
return value; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment