I have an array with values and I am wondering what would be the best approach to reduce it if value repeat for example 3 or 4 times?
I know how to remove duplicates, but what if I want the value to be repeated two times?
Let's have for example this:
let arr = [1,1,1,3,3,2,4,4,7,7,7,7]
let n = 2 //so I want numbers to repeat maximum two times
Result would be:
[1,1,3,3,2,4,4,7,7]