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

improve array.remove performance and description #196

Closed
wants to merge 1 commit into from

Conversation

kirilloid
Copy link

@kirilloid kirilloid commented Dec 16, 2017

Addressing #195
Please, look at the description, which I think now reflects real function behaviour better.
Maybe, we need to change the behaviour instead?

Copy link
Owner

@Chalarangelo Chalarangelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing! There are quite a few inconsistencies with the style guide, please update your snippet to match the styleguide. I will check if the code works as expected after the changes have been made and run performance tests to ensure that it is actually faster than the previous version.

Use `Array.filter()` to find array elements that return truthy values and `Array.reduce()` to remove elements using `Array.splice()`.
The `func` is invoked with three arguments (`value, index, array`).
Finds elements that satisfy a predicate and returns them, at the same time modifying an original array.
In other words, it works like [R#partition](http://ramdajs.com/docs/#partition), except that it mutates the original array and returns another partition instead of returning two.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

// remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
/**
* @param {E[]} arr
* @param {(E, number, E[]) => boolean}

This comment was marked as spam.

const nonMatching = arr.filter((e, i) => !func(e, i, arr));
arr.splice(0, arr.length - 1, nonMatching);
return matching;
}

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@Chalarangelo
Copy link
Owner

I'm closing this PR as it has been dead for a couple of days and there have already been a bunch of changes made to the relevant file. Feel free to make a new one if you still think there are problems that need to be addressed.

@lock
Copy link

lock bot commented Dec 18, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants