Skip to content

Instantly share code, notes, and snippets.

@vamshi9666
Created August 14, 2018 08:10
Show Gist options
  • Save vamshi9666/13306ac0c7552e95eee5d4762d77a5fa to your computer and use it in GitHub Desktop.
Save vamshi9666/13306ac0c7552e95eee5d4762d77a5fa to your computer and use it in GitHub Desktop.
const input_array = [[1,2,[3]],4]
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
flatten(input_array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment