Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function flatten( array ) {
- const output = [];
- if( !( array instanceof Array ) )
- return false;
- function recurseFlatten( array ) {
- array.forEach( (el) => {
- if( el instanceof Array ) {
- recurseFlatten( el );
- } else if ( typeof el === 'number' ) {
- output.push( el );
- }
- });
- }
- recurseFlatten( array );
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement