DEV Community

Cover image for Day 13 of JavaScriptmas - Extract Each Kth Solution
Sekti Wicaksono
Sekti Wicaksono

Posted on • Updated on

Day 13 of JavaScriptmas - Extract Each Kth Solution

Day 13 is removing the every Kth value from an array.

If an array with value [1,2,3,4,5,6,7,8,9,10] and the k is 3.
It means when an array found a number 3 or the multiplication of 3 (such as 6), remove it from the array.
The result should be [1,2,4,5,7,8,10].

This is the JavaScript solution

function extractEachKth(nums, index) {
   return nums.filter(num => num % index != 0);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)