Skip to content

Instantly share code, notes, and snippets.

@bard
Created May 17, 2021 17:23
Show Gist options
  • Save bard/cfbd32e59ef50ec2649f644f51d464b3 to your computer and use it in GitHub Desktop.
Save bard/cfbd32e59ef50ec2649f644f51d464b3 to your computer and use it in GitHub Desktop.
const partition = <T>(array: T[], pred: (item: T) => boolean) =>
array.reduce<[T[], T[]]>(
([leftSet, rightSet], item) =>
pred(item)
? [[...leftSet, item], rightSet]
: [leftSet, [...rightSet, item]],
[[], []],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment