j0hnik,
function fn(d, e) {
for (var f = [], b = {}, a, c = 0; c < d.length; c++)
a = d[c], b[a] == e || (b[a]++ || (b[a] = 1), b[a] == e && f.push(a));
return f
};
console.time("x")
for (var k=0; k<10000; k++) {
var arr = [], i=100;
while(i--) arr.push(Math.floor(Math.random() * 100));
fn(arr, 3)
}
console.timeEnd("x")
function three(arr){
return arr.filter((el, i)=> {
var s = 0;
while (i--) if (el == arr[i]) s++;
return (s>1&&s<=2);
});
}
console.time("k")
for (var k=0; k<10000; k++) {
var arr = [], i=100;
while(i--) arr.push(Math.floor(Math.random() * 100));
three(arr)
}
console.timeEnd("k")