Created
July 12, 2019 04:07
-
-
Save roshanca/8e2f2cdf2648eee8a14d91b44818db47 to your computer and use it in GitHub Desktop.
One loop two arrays #js
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 exampleValues = [2, 15, 8, 23, 1, 32]; | |
const [truthyValues, falseyValues] = exampleValues.reduce((arrays, exampleValue) => { | |
if (exampleValue > 10) { | |
arrays[0].push(exampleValue); | |
return arrays; | |
} | |
arrays[1].push(exampleValue); | |
return arrays; | |
}, [[], []]); | |
// truthyValues | |
// (3) [15, 23, 32] | |
// falseyValues | |
// (3) [2, 8, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment