Skip to content

Instantly share code, notes, and snippets.

@MAKIO135
Created September 4, 2018 10:50
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 MAKIO135/1fba099467a5d0701a8597024e235d66 to your computer and use it in GitHub Desktop.
Save MAKIO135/1fba099467a5d0701a8597024e235d66 to your computer and use it in GitHub Desktop.
flatten Arrays
// https://stackoverflow.com/questions/10865025/merge-flatten-an-array-of-arrays-in-javascript/39000004#39000004
const flatten = function(arr, result = []) {
for (let i = 0, length = arr.length; i < length; i++) {
const value = arr[i];
if (Array.isArray(value)) {
flatten(value, result);
} else {
result.push(value);
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment