Created
June 21, 2022 16:02
-
-
Save trezy/7339db16aca69b288c51671cb067273e to your computer and use it in GitHub Desktop.
Evaluating 2 versions of a JavaScript `array.reduce`
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
const valueArrays = [ | |
[1, 2], | |
[100, 400, 700], | |
] | |
const TOTAL_COMBINATIONS = valueArrays | |
.reduce((accumulator, values, index) => { | |
if (index === 0) { | |
return values.length | |
} | |
return accumulator * values.length | |
}, 0) |
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
const valueArrays = [ | |
[1, 2], | |
[100, 400, 700], | |
] | |
const TOTAL_COMBINATIONS = valueArrays | |
.map(values => values.length) | |
.reduce((accumulator, length) => (accumulatora * length)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment