function elements_that_appear_more_than_x_times(array, k) {
let size = arr.length;
let times = parseInt(size / k);
console.log("more than " + times + " times");
return array.filter((a, index) =>
array.indexOf(a) === index &&
array.reduce((accumulator, b) => +(a === b) + accumulator, 0) > times
);
}
let k = 4;
let arr = [4, 8, 6, 5, 5, 8, 3, 2, 1, 2, 2, 5, 5, 5, 5, 8, 9, 8, 8];
// 8 appear 5 times, 5 appear 6 times
console.log(elements_that_appear_more_than_x_times(arr, k));
/*
run:
more than 4 times
[ 8, 5 ]
*/