Skip to content

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

Closed

Description

@aarontravass

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

Activity

  1. braaar commented on Jan 11, 2024

    @braaar
    Member

    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.

  2. locked and limited conversation to collaborators on Jan 11, 2024
  3. converted this issue into a discussion #2367 on Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions