Skip to content

Instantly share code, notes, and snippets.

@MatthewTrout
Created October 24, 2019 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewTrout/61dc1e5fd42ee8365980375129165bcd to your computer and use it in GitHub Desktop.
Save MatthewTrout/61dc1e5fd42ee8365980375129165bcd to your computer and use it in GitHub Desktop.
es6 array flatten
export const flatten = (arr) => {
return arr.reduce((acc, curr) => {
const val = Array.isArray(curr) ? flatten(curr) : [curr];
return [...acc, ...val];
}, []);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment