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

Why Array.reduce() is needed in Array remove when we can get the same result using just Array.filter()? #179

Closed
vivek28111992 opened this issue Dec 16, 2017 · 2 comments

Comments

@vivek28111992
Copy link
Contributor

Why array reduced is used?

const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { arr.splice(arr.indexOf(val), 1); return acc.concat(val); }, []) : [];

as we can get the same result using this

const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func) : [];

Can anyone please answer this?

@Chalarangelo
Copy link
Owner

This is done to remove duplicate elements from the final result.

@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

No branches or pull requests

2 participants