Skip to content

Instantly share code, notes, and snippets.

@carinlynchin
Created July 7, 2017 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carinlynchin/83b89b23115b80bb9ba36b6bfc33fb58 to your computer and use it in GitHub Desktop.
Save carinlynchin/83b89b23115b80bb9ba36b6bfc33fb58 to your computer and use it in GitHub Desktop.
Test
var a = [[1,2,[3]],4]; // -> [1,2,3,4]
var newA = [];
function flatten(a) {
for (var i=0; i<a.length; i++) {
if (typeof a[i] != 'number') {
newA.concat(flatten(a[i]));
}
else {
newA.push(a[i]);
}
}
return newA;
}
flatten(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment