Guest User

Untitled

a guest
May 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function deleteNth(arr,n){
  2. arr.forEach(function (item, index) {
  3. var count = 0;
  4. for (var i = 0; i < arr.length; i++) {
  5. if (arr[i] === item) {
  6. count++;
  7. while (count > n) {
  8. var remove = arr.lastIndexOf(item);
  9. arr.splice(remove, 1);
  10. count--;
  11. }
  12. }
  13. }
  14. });
  15. return arr;
  16. }
  17.  
  18. deleteNth([7, 26, 21, 41, 43, 2, 26, 24, 10, 26, 10, 10, 24, 35, 35,
  19. 35, 43, 26, 41, 7, 24, 24, 21, 24, 10, 35, 10, 7, 24, 7, 35, 26, 41,
  20. 35, 2, 43, 24, 2, 41, 26, 41, 7, 7, 26, 2, 10, 43, 10, 35, 41, 24, 7,
  21. 2, 2, 7, 2, 26, 24, 26, 43, 43, 21, 10, 28, 10], 2)
  22.  
  23. [7, 26, 21, 41, 43, 2, 26, 24, 10, 10, 10, 24, 35, 35, 43, 41, 7, 21,
  24. 41, 2, 43, 28]
  25.  
  26. [7, 26, 21, 41, 43, 2, 26, 24, 10, 10, 24, 35, 35, 43, 41, 7, 21, 2,
  27. 28]
Add Comment
Please, Sign In to add comment