New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Add partition #512
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe using parens + comma operator can make it one line.
const partition = (arr, fn) =>
arr.reduce((acc, val, i, arr) => (acc[fn(val, i, arr) ? 0 : 1].push(val), acc), [[],[]]);
@atomiks I thought about it when I was writing the snippet, it looks slightly confusing like that, I feel. Plus we have a few snippets with the same kind of style, so I decided to go with that style for consistency. |
@Chalarangelo see the edit- you can also stick the ternary inside the nvm concat can't be used since it relies on mutating the inner arrays |
|
Reduce is a weird monster, but this works as advertised. To only awkward part is needing the parens, which harms readability but not enough to not consider it |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks. |
Description
Lodash #100 -> https://lodash.com/docs/4.17.4#partition
What does your PR belong to?
Types of changes
Checklist: