function chunkyMonkey(values, size) { // write code here. let result = []; let begin = 0; let end = size; const lengt...
function chunkyMonkey(values, size) {
// write code here.
let result = [];
let begin = 0;
let end = size;
const length_of_array = values.length;
const no_of_slice = values.length/size;
if(length_of_array%size == 0){
for(let i=0; i<no_of_slice;i++){
result.push(values.slice(begin,end));
begin += size;
end += size;
}
}
else{
for(let i=0; i<=no_of_slice;i++){
result.push(values.slice(begin,end));
begin += size;
end += 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"]]);
});
});
COMMENTS