Skip to content

Instantly share code, notes, and snippets.

@temitope
Created February 11, 2019 23:52
Show Gist options
  • Save temitope/65176cd84eb1c89fc2a94d0e5bb50be9 to your computer and use it in GitHub Desktop.
Save temitope/65176cd84eb1c89fc2a94d0e5bb50be9 to your computer and use it in GitHub Desktop.
WPJgGo
// 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