Skip to content

Instantly share code, notes, and snippets.

@indrajeet0510
Created September 20, 2016 10:26
Show Gist options
  • Save indrajeet0510/1083a0ce43c4269617539f89e0f3f4ac to your computer and use it in GitHub Desktop.
Save indrajeet0510/1083a0ce43c4269617539f89e0f3f4ac to your computer and use it in GitHub Desktop.
Flat Array
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