Advertisement
Guest User

Untitled

a guest
May 19th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. function flatten( array ) {
  2. const output = [];
  3.  
  4. if( !( array instanceof Array ) )
  5. return false;
  6.  
  7. function recurseFlatten( array ) {
  8. array.forEach( (el) => {
  9.  
  10. if( el instanceof Array ) {
  11. recurseFlatten( el );
  12. } else if ( typeof el === 'number' ) {
  13. output.push( el );
  14. }
  15. });
  16. }
  17.  
  18. recurseFlatten( array );
  19.  
  20. return output;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement