Sprawdź, czy tablica ma takie same wartości JavaScript
const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]); // true
TC5550
const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]); // true
function hasDuplicates(array) {
return (new Set(array)).size !== array.length;
}
const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
const count = names =>
names.reduce((a, b) => ({ ...a,
[b]: (a[b] || 0) + 1
}), {}) // don't forget to initialize the accumulator
const duplicates = dict =>
Object.keys(dict).filter((a) => dict[a] > 1)
console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
console.log(duplicates(count(names))) // [ 'Nancy' ]