Create a function that takes two arguments: an array arr and a number num. If an element occurs in arr more than num times, remove the extra occurrence(s) and return the result.
We have a set of elements and a number(occurrence limit ) . we need to find the each element's occurrence in that set which should not be more than given number. The extra occurrence than the given specified occurrence limit should be removed.
Lets take the first element, and compare it with rest all elements on the right to check it's occurrence. By doing this we get the occurrence of the first element. now we should only consider the occurrence up to the given occurrence limit .
Example limit given is 2 and we should only consider 2 occurrence of each element.
Similarly do it for all the elements.
we should display all the element's occurrences up to the given limit.
Do this without using the
.uniq
methodCreate a function that takes two arguments: an array arr and a number num. If an element occurs in arr more than num times, remove the extra occurrence(s) and return the result.
Examples
Notes Do not alter the order of the original array.