Tell us what’s happening:
I’ve got to this stage, I figure I have complicated this a bit cause the for loop in the current state seems unnecessary yet I know the for loop is crucial. I understand that the for loop needs to keep looping after pushing in the size. Help me how.
Your code so far
function chunkArrayInGroups(arr, size) {
// Break it up.
var final = [];
var bla = [];
for (var i = 0; i < arr.length; i++) {
bla.push(arr[i]);
}
var subArr = bla.slice(0, size);
final.push(subArr);
while (final.length < size) {
final.push(subArr);
}
return final;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/chunky-monkey