Skip to content
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

partitionObject #30

Open
CMEONE opened this issue Oct 31, 2021 · 3 comments
Open

partitionObject #30

CMEONE opened this issue Oct 31, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@CMEONE
Copy link
Member

CMEONE commented Oct 31, 2021

We should have a method that partitions an object based on a certain condition, like this:

helpful.partitionObject({"a": 1, "b": 2, "c": 3, "d": 4}, (key, value) => value > 2) => [{"c": 3, "d": 4}, {"a": 1, "b": 2}]

or:

helpful.partitionObject({"a": 1, "b": 2, "c": 3, "d": 4}, (key, value) => key == "a") => [{"a": 1}, {"b": 2, "c": 3, "d": 4}]

or:

helpful.partitionObject({"a": 1, "b": 2, "c": 3, "d": 4}, (key, value) => true) => [{"a": 1, "b": 2, "c": 3, "d": 4}, {}]

or:

helpful.partitionObject({"a": 1, "b": 2, "c": 3, "d": 4}, (key, value) => false) => [{}, {"a": 1, "b": 2, "c": 3, "d": 4}]

The second parameter should be a function with two arguments, which represents one key-value pair in the object. The return value should be a list containing two objects. The first object should contain all the key-value pairs where the function parameter returns a truthy value, and the second object should contain all the key-value pairs where the function parameter returns a falsey value.

The original object passed into the function should not be altered.

@CMEONE CMEONE added enhancement New feature or request good first issue Good for newcomers labels Oct 31, 2021
@Alienware237
Copy link

Hi
I would be very happy to join you in resolving this issue

@CMEONE
Copy link
Member Author

CMEONE commented Nov 11, 2021

@Alienware237 Sounds great, we look forward to seeing your PR!

@prisojacques
Copy link

Hello, I found this issue today, being a javascript fan I would like to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants