Skip to content

Instantly share code, notes, and snippets.

@karol-majewski
Last active February 2, 2023 13:48
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karol-majewski/e1a53b9abd39f3b7c3f4bf150546168a to your computer and use it in GitHub Desktop.
Save karol-majewski/e1a53b9abd39f3b7c3f4bf150546168a to your computer and use it in GitHub Desktop.
The simplest flatMap implementation in TypeScript
export function flatMap<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment