Created
August 18, 2020 01:08
-
-
Save roark47/da6b9b45a3abba95b889f13fcae89c93 to your computer and use it in GitHub Desktop.
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
| const reduce = (array, fn, initialValue) => { | |
| let accumlator | |
| if (initialValue != undefined) { | |
| accumlator = initialValue | |
| } else { | |
| accumlator = array[0] | |
| } | |
| if (initialValue === undefined) { | |
| for (let i = 1; i < array.length; i++) { | |
| accumlator = fn(accumlator, array[i]) | |
| } | |
| } else { | |
| for (const value of array) accumlator = fn(accumlator, value) | |
| } | |
| return [accumlator] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment