Created
July 7, 2020 19:44
-
-
Save jackmahoney/51018d893ac812b08b07377755b589b6 to your computer and use it in GitHub Desktop.
Flatten an array of arrays or map of arrays in Typescript single liner
This file contains hidden or 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
/** | |
* Flatten a map of arrays or array of arrays to a single array | |
* @param t | |
*/ | |
export function flatten<T>(t: Array<Array<T>> | { [p: string]: Array<T> }): Array<T> { | |
return Object.values(t).reduce((mem, val) => [...mem, ...val], []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment