Last active
February 20, 2017 20:56
-
-
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 ☄
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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