Created
February 13, 2017 15:57
-
-
Save kuznetsovandrey76/9e11db4e0c5702551558349619a87226 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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