Created
February 11, 2019 23:52
-
-
Save temitope/65176cd84eb1c89fc2a94d0e5bb50be9 to your computer and use it in GitHub Desktop.
WPJgGo
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
// For CitrusByte app | |
const control = [1, 2, 3]; | |
const simple = [[2,3]]; | |
const simpleMix = [1, [2,3]]; | |
const compound = [[0,1], [2,3]]; | |
const compoundMix = [[0,1], 0.5, [2,3]]; | |
const compoundMix2 = [[-4, -3,-2], [-1,0,1], 0.5, [2,3,4,5], 6, 7 ,8 ,9]; | |
function flattenArray(arr) { | |
if(!Array.isArray(arr) || !arr.length){ | |
console.warn('no array type or empty'); //this assumes empty arrays are not to be accounted for | |
return null; | |
} | |
return arr.map(v=>Array.isArray(v) ? flattenArray(v) : v); | |
} | |
console.log( | |
`control: ${flattenArray(control)}`, | |
`simple: ${flattenArray(simple)}`, | |
`simpleMix: ${flattenArray(simpleMix)}`, | |
`compound: ${flattenArray(compound)}`, | |
`compoundMix: ${flattenArray(compoundMix)}`, | |
`compoundMix2: ${flattenArray(compoundMix2)}`, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment