-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 3 - ChunkyMonkey.js
43 lines (32 loc) · 1.06 KB
/
Day 3 - ChunkyMonkey.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
/*Chunky Monkey
https://scrimba.com/learn/adventcalendar/note-at-0-36-cofef491c9584b734fa64ba1d
DESCRIPTION:
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
Example:
chunkyMonkey(["a", "b", "c", "d"],2) should return [["a", "b"], ["c", "d"]]
chunkyMonkey([0,1,2,3,4,5],4) should return [[0,1,2,3], [4,5]]
Hints: slice()
*/
const chunkyMonkey = (values, size) => {
const result = []
for(i=0; i < values.length; i += size) {
result.push(values.slice(i, i + size))
}
return result
}
/**
* Test Suite
*/
describe('chunkyMonkey()', () => {
it('returns largest positive integer possible for digit count', () => {
// arrange
const values = ["a", "b", "c", "d"];
const size = 2;
// act
const result = chunkyMonkey(values, size);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([["a", "b"], ["c", "d"]]);
});
});