function three(arr){ return arr.filter((el, i)=> { var s = 0; while (i--) if (el == arr[i]) s++; return (s>1&&s<=2); }); } console.log(three([5.6,435,5,6,5.3,5.6,5.6]));