-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 13 - ExtractEachKth.js
53 lines (35 loc) · 1.07 KB
/
Day 13 - ExtractEachKth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*Extract Each Kth
https://scrimba.com/scrim/coc534d6cb36fae15e6d67bcf
DESCRIPTION:
Given an array of integers, remove each kth element from it.
Example:
For inputArray = [1,2,3,4,5,6,7,8,9,10] and k = 3, the output should be extractEachkth(inputArray, k) = [1,2,4,5,7,8,10]
Hints: filter()
*/
function extractEachKth (arr, element) {
function division (value, index) {
return (index + 1) % element !== 0
}
const result = arr.filter(division)
return result
}
//or:
function extractEachKth(arr, element) {
return arr.filter((value, index) => (index + 1) % element !== 0)
}
/**
* 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]);
});
});