Skip to content

Instantly share code, notes, and snippets.

@TheBox193
Created April 25, 2016 15:23
Show Gist options
  • Save TheBox193/47fcf5cdf3074ddfc0b2c57617c7448d to your computer and use it in GitHub Desktop.
Save TheBox193/47fcf5cdf3074ddfc0b2c57617c7448d to your computer and use it in GitHub Desktop.
/**
* Recursivly flatten a deeply nested array
* @arr Array Array with nested values
* @return Array Flattend array
*/
function flatten(arr) {
return arr.reduce(function(result, current) {
if (current instanceof Array) {
return result.concat(flatten(current));
} else {
result.push(current);
return result;
}
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment