Open kartamyshev opened 4 years ago
function allValuesAreEqualTo (arr, value) {
let result = true;
for (const item of arr) {
if (item !== value) {
result = false;
break;
}
}
return result;
}
function allValuesAreEqualTo (arr, value) {
let counter = arr.reduce((result, current) => {
(current === value) ? result++ : result;
return result;
}, 0);
return (counter === arr.length) ? true : false;
}
console.log(allValuesAreEqualTo([2, 2, 2, 2], 2));
Example: