Given a list
lst and a number
N, create a new list that contains each number in
lst at most
N times without reordering.
For example if
N = 2, and the input is
[1,2,3,1,2,1,2,3], you take
[1,2,3,1,2], skip the next 1 and 2 because this would lead to those numbers being in the result more than
N times. Finally, take 3, which leads to
deleteNth([1,1,1,1],2) // return [1,1]
deleteNth([20,37,20,21],1) // return [20,37,21]
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!