News for hackers. Stuff that matters.
Re:New JavaScript Set Methods by moritzwarhier on Monday June 24, 2024 @12:45PM (#40778212)
It's a pretty straightforward way to do things like avoiding duplicates or checking if an item is part of a collection without using quadratic loops or string-keyed dictionary objects.

It's O(1) for the latter (edit: I stand corrected, but probably close, as per spec).

Conversion to and from arrays even preserves order.

So I don't see these two use cases as "showing off", why should anybody do that?

Re:New JavaScript Set Methods by lelandfe on Monday June 24, 2024 @12:48PM (#40778257)
I have only used JS sets in interviews to avoid duplication - more than once, the interviewer has chuckled appreciatively and directed me to not use them (being too easy)
Re:New JavaScript Set Methods by y-c-o-m-b on Monday June 24, 2024 @01:57PM (#40778904)
That would be a red flag for me in most cases, as the person being interviewed. If the interview is to gauge my knowledge of Javascript, then using sets should be in my favor since I'm using the most optimized approach to demonstrate I know the language well and can adequately do the job. If it's "not acceptable", then what is the goal there? To wrack my brain as part of some pseudo intelligence test? Shall we break it down to 1s and 0s too?
Re:New JavaScript Set Methods by kevincox on Monday June 24, 2024 @04:16PM (#40780200)
It can be a point in your favour but also something that you are asked to avoid. You both showed good knowledge and default choices and showed that you can implement a simple algorithm from scratch. Both are valuable points about your skills.

The main "result" of the interview shouldn't just be "does the code work". The process is far, far more important for understanding how you write code.

Re:New JavaScript Set Methods by moritzwarhier on Monday June 24, 2024 @12:49PM (#40778267)
Fair, and that's actually the opposite of using them to show off, right? :)