Created
July 7, 2017 14:08
-
-
Save carinlynchin/83b89b23115b80bb9ba36b6bfc33fb58 to your computer and use it in GitHub Desktop.
Test
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
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