Created
July 18, 2022 19:24
-
-
Save forivall/e7c4cc44015c39f1e62b9869661df158 to your computer and use it in GitHub Desktop.
reduce based partition function
This file contains 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
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