Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function deleteNth(arr,n){
- arr.forEach(function (item, index) {
- var count = 0;
- for (var i = 0; i < arr.length; i++) {
- if (arr[i] === item) {
- count++;
- while (count > n) {
- var remove = arr.lastIndexOf(item);
- arr.splice(remove, 1);
- count--;
- }
- }
- }
- });
- return arr;
- }
- deleteNth([7, 26, 21, 41, 43, 2, 26, 24, 10, 26, 10, 10, 24, 35, 35,
- 35, 43, 26, 41, 7, 24, 24, 21, 24, 10, 35, 10, 7, 24, 7, 35, 26, 41,
- 35, 2, 43, 24, 2, 41, 26, 41, 7, 7, 26, 2, 10, 43, 10, 35, 41, 24, 7,
- 2, 2, 7, 2, 26, 24, 26, 43, 43, 21, 10, 28, 10], 2)
- [7, 26, 21, 41, 43, 2, 26, 24, 10, 10, 10, 24, 35, 35, 43, 41, 7, 21,
- 41, 2, 43, 28]
- [7, 26, 21, 41, 43, 2, 26, 24, 10, 10, 24, 35, 35, 43, 41, 7, 21, 2,
- 28]
Add Comment
Please, Sign In to add comment