Skip to content

feat: unique elements#16

Open
adeyahya wants to merge 1 commit intomainfrom
feat/find-duplicate
Open

feat: unique elements#16
adeyahya wants to merge 1 commit intomainfrom
feat/find-duplicate

Conversation

@adeyahya
Copy link
Copy Markdown
Collaborator

Summary

  • filter duplicate elements and return it's indexs
  • deep compare ( wrapping react-fast-compare )

Copy link
Copy Markdown

@mirzadipradhana mirzadipradhana left a comment

Choose a reason for hiding this comment

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

i think it's o(n2) since it has a loop inside of loop with quadratic linear iteration #cmiiw
we had many approaches to solving this problem, how about we try a performance test to compare each of the solutions? 😄


const current = a[i];
const duplicateIndexs = [];
for (let j = i + 1; j < a.length; j++) {
Copy link
Copy Markdown

@mirzadipradhana mirzadipradhana May 19, 2021

Choose a reason for hiding this comment

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

^ this one

Copy link
Copy Markdown
Collaborator Author

@adeyahya adeyahya May 19, 2021

Choose a reason for hiding this comment

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

indeed it requires 2 loop, but it has circuit breaker to exit the loop if the item already checked and has duplication, and I think I should early exit also on the second loop. no Idea how to solve this with one loop haha

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

😄 since all of the solutions might have similar o notation, let's try to compare the performance when we get a chance

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.

2 participants