DIVIDE ET IMPERA ваша проблема :)
найдите отдельные имена в вашем списке
для каждого элемента предыдущего шага, посчитайте, как много раз оно есть в вашем списке.
Найдите отдельное имя в своем списке:
//create a new array and suppose it has as many elements as the given input:
let ris = new array[input.length]
//define an index for this array.
let k = 0
//in the rest of the algorithm let always k be the actual length of ris and the next possible index to use
//let's start iterating over the input list
for (i = 0; i<input.length; i++) {
//let's check if input[i] it's already present in ris
//we can look just for the first k elements
let addCurrentName = true
for (j = 0; j<k; j++) {
if (input[i] == ris[j]) addCurrentName = false;
}
if (addCurrentName) {
//we go inside this if only if in the previous search we found nothing
ris[k] = input[i];
k++;
}
}
//now the first k positions of ris contain the distinct values of input
let ris2 = new array[k] //now we are sizing the result exactly
for (i = 0; i<k; i++) {
ris2[i] = ris[i] //we are just creating the result of the right dimension and copying values into it
}
return ris2;
Вы сказали, что уже знаете, как подсчитать, сколько раз элемент находится в массиве, поэтому остальное я оставлю вам, вам просто нужно сделать это для всех отдельных значений.