Skip to content

Instantly share code, notes, and snippets.

@jackmahoney
Created July 7, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmahoney/51018d893ac812b08b07377755b589b6 to your computer and use it in GitHub Desktop.
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
/**
* 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