Last active
May 2, 2025 17:18
-
-
Save funador/9a39bf6f70bcef7fe2627bc9943a7d29 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
| Array.prototype.myReduce = function(func, initialValue) { | |
| const arr = arguments.length > 1 | |
| ? [initialValue, ...this] | |
| : this | |
| let accumulator = arr[0] | |
| for (let i = 1; i < arr.length; i++) { | |
| accumulator = func(accumulator, arr[i], i, this) | |
| } | |
| return accumulator | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment