Last active
September 9, 2019 20:30
-
-
Save ravi0402/d18b67103c3c76a4cad9f3d23b0e93fb to your computer and use it in GitHub Desktop.
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
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
const arrayFlatten = (arr) => { | |
if (!Array.isArray(arr))return 'The input provided is not an array'; | |
return arr.reduce((x, y) => { | |
if (Array.isArray(y)) return x.concat(arrayFlatten(y)); | |
return x.concat(y) | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment