Skip to content

Instantly share code, notes, and snippets.

@jadechip
Last active February 20, 2017 20:56
Show Gist options
  • Save jadechip/c248460a182b4b2a4f3af8104b6a270b to your computer and use it in GitHub Desktop.
Save jadechip/c248460a182b4b2a4f3af8104b6a270b to your computer and use it in GitHub Desktop.
Converts a multi-dimensional, intergalactic space array into the much more tame singular dimension - Made for CitrusByte ☄
var pancake = function pancake(inputArray) {
return inputArray.reduce(function (accumulation, value) {
if(Array.isArray(value)) {
return accumulation.concat(pancake(value));
} else {
return accumulation.concat(value);
}
}, []);
};
var testArray = [[1,2,[3]],4];
console.log(pancake(testArray));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment