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...
For further actions, you may consider blocking this person and/or reporting abuse
Just joined the community! I guess reducer is overkill here but still 🤷
Hmm... I wonder what happens if
deleteNth
is invoked more than once :Phaha, you re right! Missed that one. Moved the obj initialisation inside the func.
JavaScript
Scala
Javascript Map:
Haskell:
Clojure
recur
-based version, for comparison's sake:Java
JS solution
C++
std::vector deleteNth(const std::vector& lst, int n)
{
std::vector out;
std::map count;
for(auto i : lst)
{
if(count[i] < n)
{
count[i] = count[i] + 1;
out.push_pack(i);
}
}
return out;
}
TypeScript