"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Codewars - Delete elements that appear more than n times

Codewars - Delete elements that appear more than n times

Posted on 2025-04-18
Browse:578

Salutations.

Codewars - Delete occurrences of an element if it occurs more than n times

I'm posting Codewars challenges and my thought process in this series. I'm using JS and Node 18 whenever possible. Just for the sake of clarity, I'm making fair use of them.

"Delete occurrences of an element if it occurs more than n times". In essence, trim parts in the middle of the array, without altering the order.

function deleteNth(arr,n){
  let counter = {"top": n , "undef": 0};

  for (let i = 0 ; i  0);

  for (let i = 0 ; i 



It... works. Needs refactoring since it clearly doesn't follow any good practices, but I'm gonna move on to the next challenge.

Take care. Drink water ???.

Previous

Release Statement This article is reproduced at: https://dev.to/dantedinopegassi/codewars-delete-occurrences-of-an-element-if-it-occurrs-more-than-n-times-2g9g?1 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3