Skip to content

Instantly share code, notes, and snippets.

@MikeDigitize
Last active February 25, 2016 19:38
Show Gist options
  • Select an option

  • Save MikeDigitize/05d733719a159457cfc7 to your computer and use it in GitHub Desktop.

Select an option

Save MikeDigitize/05d733719a159457cfc7 to your computer and use it in GitHub Desktop.
function stillContainsArray(arr) {
return arr.some(item => item instanceof Array);
}
function concat(arr) {
return arr.reduce((a,b) => a.concat(b), []);
}
function flatten(arr) {
while(stillContainsArray(arr)) {
arr = concat(arr);
}
return arr;
}
var arr = [1,2,3,4,[5,5,[1,1,1],6,7],[1,2,[2,3,[100,[23,45,11,[600,599]],101,99],4],3]];
flatten(arr).sort((a,b) => a - b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment