const mostLeastAndTheRest = names => {
const dict = names.reduce((acc, name) => ((acc[name] ??= 0), acc[name]++, acc), {});
// { "Женя": 3, "Иван": 1, "Виктор": 4, "Константин": 1 }
const values = Object.values(dict);
const max = Math.max(...values);
const min = Math.min(...values);
const entries = Object.entries(dict);
const winners = entries.filter(([_, value]) => value === max).map(([key, _]) => key);
const losers = entries.filter(([_, value]) => value === min).map(([key, _]) => key);
const rest = Object.keys(dict).filter(name => !winners.includes(name) && !losers.includes(name));
return { winners, losers, rest };
};
mostLeastAndTheRest(['Женя', 'Женя', 'Иван', 'Женя', 'Виктор', 'Виктор', 'Константин', 'Виктор', 'Виктор']);
/*
{
"winners": [ "Виктор" ],
"losers": [ "Иван", "Константин" ],
"rest": [ "Женя" ]
}
*/