Skip to content

Simplify array_unique #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Simplify array_unique #3

wants to merge 1 commit into from

Conversation

timmarinin
Copy link

Use Array.prototype.indexOf instead of custom key comparator.

This change probably makes function slower due to indexOf probable O(n) timing,
but clarity of the code is more important than the performance in this case.

Use Array.prototype.indexOf instead of custom key comparator.

This change probably makes function slower due to indexOf probable O(n) timing,
but clarity of the code is more important than the performance in this case.
Copy link
Owner

@amitmerchant1990 amitmerchant1990 left a comment

Choose a reason for hiding this comment

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

It failed to pass the following case:

array_unique([{a: 'val'}, {b: 'val', c: 'val'}, 'a', 'b', [1,2,3,4], {a: 'val'}, [1,2,3,4], [{a: 'val'}, {b: 'val'}], [{a: 'val'}, {b: 'val'}]]);
// [{a: 'val'}, {b: 'val', c: 'val'}, 'a', 'b', [1,2,3,4], [{a: 'val'}, {b: 'val'}]]

Can you please check?

@atk
Copy link

atk commented Sep 22, 2017

indexOf will only compare the content's indices, not it's contents if those are objects, arrays or NaN. Therefore, this breaks the current functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants