j0hnik,
спасибо, но не может быть, чтобы мой цикл длиной скажем в 10 символов был медленнее вашего на 50.
var arr = [127,3627,65,58,8527,87,1365,1,27,47,7,89,55,11,2727,3636,4747,77,88,556,66,78,55,4747,6,8,47,7,5,67,47,36,475,678,4736,272747,56,7,5,36,27,47,3627,271,27,477,9547,88,3678,156,875,1275,1475,98,751,27547,2756,1547,785,1276,1477,2758,3669,4756,789,12736,12736,4758,785,1275,1475,6547,785,9547,789,156,12747,12747,12747,127547,178,1547,1547,78,69,75,12751,785,987,5477,5477,58,16,178,198,1477,1477,3657,5471,4747,47478,6476,87647,865,5477,587,87,9,6,5,47,8,5,536,568,6847,689,515,789,12756,1547,1475,7471,2758,63627,847,1275,627,58,86,476,127,5727,6547,1477,5366,27477,3669,1547,2775,471,275,98,87,547,271,3627,65,98,87,547,275,366,147,7478,58,96,59,475,65,81,581,1277,157,178,1475,1277,118,117,1477,1471,785,5477,1477,1478,1275,14747,1471,711,4771,4755,175,175,117,6547,1477,1477,7547,175,156,86,547,547,85,88,7,85,85,747,55,8475,75,475,85,87,7475,55,75,55];
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")
var x = fn(arr, 3);
console.timeEnd("x")
alert(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")
var k = three(arr);
console.timeEnd("k")
alert(k);