loading...

re: And then the interviewer asks, "Can you do this with less code?" VIEW POST

FULL DISCUSSION
 

You can do it with less code, the parenthesis can be omitted here. :P

const duplicateCheck = a => new Set(a).size !== a.length;
 

If you are going to assume a is an array, then you could even use !=.

 

Haha, I thought so too. And I guess we could use let instead of const since it's one letter less.

const duplicateCheck = a => a.length - new Set(a).size;

Shorter and more useful since it returns the number of duplicates

const duplicateCount = a => a.length - new Set(a).size;

And now with a meaningful name. Because, what does duplicateCheck mean, that is has, or does not have duplicates. For the boolean version hasDuplicates would be the better name.

code of conduct - report abuse