Skip to content

Instantly share code, notes, and snippets.

@andreyshedko
Last active July 5, 2019 10:49
Show Gist options
  • Save andreyshedko/b0ed0e0970f5501b6daef090e4a76974 to your computer and use it in GitHub Desktop.
Save andreyshedko/b0ed0e0970f5501b6daef090e4a76974 to your computer and use it in GitHub Desktop.
Flattening array
const x = [[1,2,[3]],4];
const flat = (arr) => {
if (Array.isArray(arr)) {
return arr.reduce((prev,curr) => {
return prev.concat(flat(curr));
}, []);
} else {
return arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment