Skip to content
Advertisement

Remove elements from a List at a specific index

I am trying to program a method that deletes the first, second and third element of every group of 4 elements. It seems not working at all. Could anyone please help?

JavaScript

Advertisement

Answer

My take…does not require the size precondition check but you may want to still catch that if it represents an error of broader scope than this method.

Given this test code…

JavaScript

the ‘zeilen’ loop can be implemented as …

JavaScript

and produces

JavaScript

Works with any length list leaving every ‘4th’ element in list.

A few more test cases :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement