Hi! I have a problem with the loop as I understood, but I don’t know what is the bug. I mean, I understand that the condition is not correct but what exactly???
I thought that my code is logical. Please, help. I would be very grateful.
Sorry, if I asked a stupid question. Just learning!
function chunkArrayInGroups(arr, size) {
let one = [];
let two = [];
let everything = [];
for (let i = 0; i < size; i++) {
one.push(arr[i]);
}
for (let j = size; j < arr.length; j++) {
two.push(arr[j]);
}
everything.push(one, two);
return everything;
}
console.log(chunkArrayInGroups(["a", "b", "c", "d"], 2)); //[ [ 'a', 'b' ], [ 'c', 'd' ] ]
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)); // [[0, 1, 2], [3, 4, 5]]
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)); //what I need: [[0, 1], [2, 3], [4, 5]], what I get: [ [ 0, 1 ], [ 2, 3, 4, 5 ] ]
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)); // what I need: [[0, 1, 2], [3, 4, 5], [6]] what I get: [ [ 0, 1, 2 ], [ 3, 4, 5, 6 ] ]
Challenge: Chunky Monkey
Link to the challenge: