Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten array using recursion. #1

Open
Ashwin7mak opened this issue Mar 1, 2019 · 1 comment
Open

Flatten array using recursion. #1

Ashwin7mak opened this issue Mar 1, 2019 · 1 comment

Comments

@Ashwin7mak
Copy link

We can flatten multi dimensional array using recursion in this way.

const flatten_array = arr => {
// Concat given array with an empty array
let flatten = [].concat(...arr);
// Check if the flatten array contains any further array
// If so do recursion of that array else return the array
return flatten.some(Array.isArray) ? flatten_array(flatten) : flatten;
}

@rohan-paul
Copy link
Owner

that looks nice and compact. Thanks @Ashwin7mak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants