Last active
January 25, 2020 07:24
-
-
Save sketchbuch/9334637b750f456b7068a07dcb026c79 to your computer and use it in GitHub Desktop.
JS - My own version of array.reduce - based on a video by MPJ (FunFunFunction)
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 numbers = [1, 2, 3] | |
const result = numbers.reduce((acc, cur) => acc += cur, 0) | |
result //? | |
const summr = (total, addition) => total + addition | |
const myReducer = (reducerFunc, initialValue, arr) => { | |
let accumilation = initialValue | |
for (let i = 0; i < arr.length; i++) { | |
accumilation = reducerFunc(accumilation, arr[i]) | |
} | |
return accumilation | |
} | |
const test = myReducer(summr, 0, numbers) | |
test //? | |
const summrTest = summr(10, 2) //? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment