Tell us what’s happening:
I just don’t understand why this won’t work, how is it an infinite loop?
*edit, I solved it on my own with a whole other approach, but I still don’t understand what was previously wrong…
Your code so far
function chunkArrayInGroups(arr, size) {
var array = [];
var iter = Math.ceil(arr.length / size);
for (var i=0; i<iter; i++) {
//newCodeBelow
var x = i*size;
array.push(arr.slice(x, x+size));
//newCodeAbove,oldCommentedCodeBelow
/* for (var x=0; x<=arr.length-size; x+size) {
for (var z=size; z<=arr.length; z+size) {
array.push(arr.slice(x, z));
}
}*/
}
return array;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2)
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 OPR/50.0.2762.67
.
Link to the challenge:
https://www.freecodecamp.org/challenges/chunky-monkey