Created
September 20, 2016 10:26
-
-
Save indrajeet0510/1083a0ce43c4269617539f89e0f3f4ac to your computer and use it in GitHub Desktop.
Flat Array
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
function parseElem(elem){ | |
if(typeof elem == 'number'){ | |
return [elem]; | |
} | |
var result = []; | |
for(var count =0; count < elem.length; count++){ | |
result = result.concat(parseElem(elem[count])); | |
} | |
return result; | |
} | |
var input = [[1,2,[4,7]],5,8,[5,[4,7,[21,34],67],23],9]; | |
var output = parseElem(input); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment