scrimba
Note at 0:44
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:44
AboutCommentsNotes
Note at 0:44
Expand for more info
main.js
run
preview
console
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]);
});
});
Console
"result: "
,
[
1
,
2
,
4
,
5
,
7
,
8
,
10
]
,
/index.html
LIVE