Created
April 11, 2015 15:18
-
-
Save IPRIT/dd83ed5b077e5d8eae91 to your computer and use it in GitHub Desktop.
Example own implemenation of reduce function similar to use Array#reduce
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 reduce(arr, fn, prev) { | |
| prev = prev || {}; | |
| if (!arr.length) { | |
| return prev; | |
| } | |
| var cur = fn(prev, arr.shift()); | |
| return reduce(arr, fn, cur); | |
| } | |
| module.exports = reduce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment