Skip to content

Instantly share code, notes, and snippets.

@forivall
Created July 18, 2022 19:24
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 forivall/e7c4cc44015c39f1e62b9869661df158 to your computer and use it in GitHub Desktop.
Save forivall/e7c4cc44015c39f1e62b9869661df158 to your computer and use it in GitHub Desktop.
reduce based partition function
export const partition = <T>(
arr: T[],
iteratee: (value: T, index: number, array: T[]) => any
) =>
arr.reduce(
(result: [T[], T[]], value, index, array) => (
result[+!iteratee(value, index, array)].push(value), result
),
[[], []]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment