DEV Community

Discussion on: And then the interviewer asks, "Can you do this with less code?"

 
jonrandy profile image
Jon Randy 🎖️
const duplicateCheck = a => a.length - new Set(a).size;

Shorter and more useful since it returns the number of duplicates

Thread Thread
 
elmuerte profile image
Michiel Hendriks • Edited
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.