Created
November 30, 2018 22:27
-
-
Save SephReed/47db051195600bc0734fa7e68b8738d0 to your computer and use it in GitHub Desktop.
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
interface ILayered extends Array<number | ILayered> { } | |
function flatten(flattenMe: ILayered) { | |
const flat: number[] = []; | |
const permeate = (layered: ILayered) => { | |
layered.forEach((item) => { | |
if(Array.isArray(item)) { | |
permeate(item); | |
} else { | |
flat.push(item); | |
} | |
}) | |
} | |
permeate(flattenMe); | |
return flat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Written in Typescript, uses recursive pattern.