Skip to content

Instantly share code, notes, and snippets.

@piotrjaw
Created February 26, 2019 13:53
Show Gist options
  • Save piotrjaw/2a1b7e12c6cdd31f07062d5fdcf3359b to your computer and use it in GitHub Desktop.
Save piotrjaw/2a1b7e12c6cdd31f07062d5fdcf3359b to your computer and use it in GitHub Desktop.
const flatten = (arr) => {
const result = [];
const _flatten = (arrayOrValue) => {
if (Array.isArray(arrayOrValue)) {
arrayOrValue.map(_flatten);
} else {
result.push(arrayOrValue);
}
};
arr.map(_flatten);
return result;
};
export default flatten;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment