Skip to content

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