Skip to content

Instantly share code, notes, and snippets.

@romanbsd
Last active June 8, 2023 09:16
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 romanbsd/7d6f1781cc1e523e81afa4d2aa21818f to your computer and use it in GitHub Desktop.
Save romanbsd/7d6f1781cc1e523e81afa4d2aa21818f to your computer and use it in GitHub Desktop.
flatten.js
export default function flattenArray(arr) {
return arr.reduce(function (flatArray, element) {
if (Array.isArray(element)) {
return flatArray.concat(flattenArray(element));
} else {
return flatArray.concat(element);
}
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment