Created
June 6, 2024 16:34
-
-
Save romgrk/7e6201cf9c1f3bd65f9da8cd45475fc3 to your computer and use it in GitHub Desktop.
reduce for valdemar <3
This file contains 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(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