A simple way is to use a Set
.
function doesContainDups(array) {
let set = new Set(array);
return set.size !== array.length;
}
console.log(doesContainDups(["item1", "item2", "item3"]));
console.log(doesContainDups(["item1", "item2", "item1"]));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…