const getModes = () => {
let frequency = [];
let maxFreq = 0;
let modes = [];
for (let i in data){
frequency[data[i].value] = (frequency[data[i].value] || 0) + 1;
if (frequency[data[i].value] > maxFreq) {
maxFreq = frequency[data[i].value];
}
}
for (let j in frequency) {
if (frequency[j] === maxFreq) {
modes.push(j);
}
}
if ( maxFreq === 1) {
return ' - '
}
if (!modes.length) {
return ' - '
}
return modes.join(', ')
}
if ( maxFreq === 1) {
после пушев.if (!modes.length) {
вообще бесполезный.const getModes = (data) => {
let most = 2;
const count = {};
const modes = data.reduce((acc, { value }) => {
const curr = (count[value] || 0) + 1;
count[value] = curr;
if(curr > most) {
most = curr;
acc.length = 0;
acc.push(value);
} else if(curr === most) {
acc.push(value);
}
return acc;
}, []);
if(modes.length === 0) {
return ' - ';
}
return modes.join(', ');
}
index == 0
для чего?