Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Flattens an array, e.g. [[1,2,[[[3]]]],4] => [1, 2, 3, 4]
var flattenArray = (array) => {
let initialValue = [];
return array.reduce((result, ele) => {
if (Array.isArray(ele)) {
let flat = flattenArray(ele);
return result.concat(flat);
} else {
result.push(ele);
return result;
}
}, initialValue);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.