let arr= [1,3,2,3,1,1,3,2,7];
function getRepetition(arr, n){
//code
};
getRepetition(arr,1)//return [7] - 7-ка встречается 1 раз
getRepetition(arr,3)//return [1,3]1 и 3-ка встречается 3 раза
getRepetition(arr,4)//return [] 4 раза ни встречается ничего
const getRepetition = (arr, repeated) => Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((acc, n) => (n[1] === repeated && acc.push(n[0]), acc), []);
function getRepetition(arr, repeated) {
const result = [];
const count = {};
for (const n of arr) {
if (!count.hasOwnProperty(n)) {
count[n] = 0;
}
count[n]++;
}
for (const n in count) {
if (count[n] === repeated) {
result.push(+n);
}
}
return result;
}