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) {
// write code here.
let splitValues = [];
let count = 0;
// let sliceFront = values.slice(0, size);
// let sliceBack = values.slice(size);
// splitValues.push(sliceFront);
// splitValues.push(sliceBack);
while (count < values.length) {
splitValues.push(values.slice(count, count+=size))
}


return splitValues;
}


// Instructor Solution. I did a much different solution here. my solution works for this case, the while lop use in the instructor solution allows this to scale. This means my solution is incorrect because it would only work on the problem case.

// function chunkyMonkey(values, size) {
// const nested = [];
// let count = 0;

// while(count < values.length) {
// nested.push(values.slice(count, count += size));
// }

// return nested;
// }



/**
* 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"]]);
});
});
Console
"result: "
,
[
[
"a"
,
"b"
]
,
[
"c"
,
"d"
]
]
,
/index.html
LIVE