Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

feature: Use a Set to check for uniqueness in Array #2210

Closed
aarontravass opened this issue Aug 21, 2023 · 1 comment
Closed

feature: Use a Set to check for uniqueness in Array #2210

aarontravass opened this issue Aug 21, 2023 · 1 comment
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.

Comments

@aarontravass
Copy link

Description

The current @ArrayUnique uses a filter based method to compare objects. This is an O(n^2) solutions. The JS spec for Set states that

The specification requires sets to be implemented "that, on average, provide access times that are sublinear on the number of elements in the collection". Therefore, it could be represented internally as a hash table (with O(1) lookup), a search tree (with O(log(N)) lookup), or any other data structure, as long as the complexity is better than O(N).

Hence, I believe it would be more performant to use a Set based approach to check for uniqueness.

Proposed solution

Something as simple as

Array.from(new Set(inputArray)).length == inputArray.length
@aarontravass aarontravass added flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features. labels Aug 21, 2023
@braaar
Copy link
Member

braaar commented Jan 11, 2024

I'm moving this to the discussion tab, as we are trying to keep the issue count low. Please see this issue for an explanation.

@typestack typestack locked and limited conversation to collaborators Jan 11, 2024
@braaar braaar converted this issue into discussion #2367 Jan 11, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.
Development

No branches or pull requests

2 participants