function extractEachKth(nums, index) {
return nums.filter(function (num, arrayIndex){
//check if it's the first index, return it..
if(arrayIndex !== 0){
//Check the next index is divisible by the index number provided, and return true if
not to return it. If it is divisble return false.
if (((arrayIndex+1)/index)%1 === 0){
return false;
}else{
return true;
}
}else{
return true;
}
});
}
/**
* Test Suite
*/
describe('extractEachKth()', () => {
it('returns largest positive integer possible for digit count', () => {
// arrange
const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const index = 3;
// act
const result = extractEachKth(nums, index);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([1, 2, 4, 5, 7, 8, 10]);
});
});