Skip to content

Instantly share code, notes, and snippets.

@romgrk
Created June 6, 2024 16:34
Show Gist options
  • Save romgrk/7e6201cf9c1f3bd65f9da8cd45475fc3 to your computer and use it in GitHub Desktop.
Save romgrk/7e6201cf9c1f3bd65f9da8cd45475fc3 to your computer and use it in GitHub Desktop.
reduce for valdemar <3
function reduce(array, callback, initial) {
let accumulator = initial
for (let i = 0; i < array.length; i++) {
let currentValue = array[i]
accumulator = callback(accumulator, currentValue)
}
return accumulator
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment