Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. function flatten(input) {
  2. var output = [];
  3. for(var i=0; i<input.length; i++) {
  4. if(Array.isArray(input[i])) {
  5. output = output.concat(flatten(input[i]));
  6. } else {
  7. output = output.push(input[i]);
  8. }
  9. return output;
  10. }
  11.  
  12. flatten([[1,2,[3]],4]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement