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
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.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// 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.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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. |
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. |
Addressing #195
Please, look at the description, which I think now reflects real function behaviour better.
Maybe, we need to change the behaviour instead?