Array duplicate removal for duplicates exceeding `N`-number
As you expected, there is a much simpler way to do this. 


Create a map where the keys are the numbers in the array and the value is the number of times each number appears in the array.
Filter the input array for any numbers that appear less than X times.




function removeMany(numbers, max) {
    const numberMap = numbers.reduce((map, num) =&gt; {
        map[num] = map[num] ? map[num] + 1 : 1;
        return map;
    }, []);
    
    return numbers.filter(num =&gt; numberMap[num] &lt; max);
}

const numbers = [1, 2, 3, 2, 4, 4, 5, 5, 5, 5];
console.log(removeMany(numbers, 3));