Skip to content

Instantly share code, notes, and snippets.

@kuznetsovandrey76
Created February 13, 2017 15:57
Show Gist options
  • Save kuznetsovandrey76/9e11db4e0c5702551558349619a87226 to your computer and use it in GitHub Desktop.
Save kuznetsovandrey76/9e11db4e0c5702551558349619a87226 to your computer and use it in GitHub Desktop.
var array = [1,2,[1,2,[[1,2,3],1,2,3],3],3];
function newarr(source) {
var res = [];
function doit(_source) {
_source.forEach(function(e) {
if(typeof e === 'number') {
// console.log("ok");
res.push(e);
} else {
// console.log("not ok");
doit(e);
}
});
}
doit(source);
return res;
}
newarr(array); // [ 1, 2, 1, 2, 1, 2, 3, 1, 2, 3, 3, 3 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment