Skip to content
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

chore: implemented a O(n) unique and added unit tests #4429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nadr0
Copy link
Collaborator

@nadr0 nadr0 commented Nov 7, 2024

Jon, Lee, and myself came across this block of code when debugging a codemirror issue. I wanted to make this code quicker and more straight forward. I also added unit tests.

Copy link

qa-wolf bot commented Nov 7, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Nov 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Nov 7, 2024 10:24pm

*/
makeUniqueDiagnostics(duplicatedDiagnostics: Diagnostic[]): Diagnostic[] {
const uniqueDiagnostics: Diagnostic[] = []
const seenDiagnostic: { [key: string]: boolean } = {}
Copy link
Collaborator

@jtran jtran Nov 8, 2024

Choose a reason for hiding this comment

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

Why not use a Set()?

Copy link
Collaborator Author

@nadr0 nadr0 Nov 8, 2024

Choose a reason for hiding this comment

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

I didn't use set because the objects are different and the content is the same. So I cannot do a .has check because it does not look at the keys, it looks at the object.

var a = new Set()
var b = {myVal:4}
var c = {myVal:4}

a.add(b)
a.has(c) --> false

Copy link
Collaborator

@jtran jtran Nov 8, 2024

Choose a reason for hiding this comment

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

You could use the string that you made as the value in the set. JS objects are not sets. They have different performance characteristics. At our scale, probably doesn't matter, but it seemed natural.

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