scrimba
Solution for day 3 of #javascriptmas
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

Solution for day 3 of #javascriptmas
AboutCommentsNotes
Solution for day 3 of #javascriptmas
Expand for more info
main.js
run
preview
console
function chunkyMonkey(values, size) {
let resultArray = [];
let position = 0;
for (i=0; i < values.length; i++) {
resultArray.push(values.slice(position, position + size));
position += size;
if (position >= values.length) { break }
}
return resultArray
}



/**
* Test Suite
*/
describe('chunkyMonkey()', () => {
it('returns largest positive integer possible for digit count', () => {
// arrange
const values = ["a", "b", "c", "d", "1", "2", "3", "4"];
const size = 2;

// act
const result = chunkyMonkey(values, size);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([["a", "b"], ["c", "d"], ["1", "2"], ["3", "4"]]);
});
});
Console
"result: "
,
[
[
"a"
,
"b"
]
,
[
"c"
,
"d"
]
,
[
"1"
,
"2"
]
,
[
"3"
,
"4"
]
]
,
/index.html
LIVE