Skip to content

Instantly share code, notes, and snippets.

@funador
Last active May 2, 2025 17:18
Show Gist options
  • Save funador/9a39bf6f70bcef7fe2627bc9943a7d29 to your computer and use it in GitHub Desktop.
Save funador/9a39bf6f70bcef7fe2627bc9943a7d29 to your computer and use it in GitHub Desktop.
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