-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: main
Are you sure you want to change the base?
Conversation
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
*/ | ||
makeUniqueDiagnostics(duplicatedDiagnostics: Diagnostic[]): Diagnostic[] { | ||
const uniqueDiagnostics: Diagnostic[] = [] | ||
const seenDiagnostic: { [key: string]: boolean } = {} |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.