-
Notifications
You must be signed in to change notification settings - Fork 844
feature: Use a Set to check for uniqueness in Array #2210
Copy link
Copy link
Closed
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.
Description
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.lengthReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.