Tell us what’s happening:
The below code works for only one case and I understand that now. I also know that a for loop is inevitable to solve for all cases.
My question is why would you want to use a for loop?
I have a feeling that arithmetic would be a better, simpler focus (I would just have to figure out a way to organize my variables so that the arithmetic was focused and more streamlined.)
However, I have also only been doing JS for four months so my feelings are questionable to say the least.
Help please.
Your code so far
function chunkArrayInGroups(arr, size) {
var newArr = [];
let num = arr.length/size;
var arrSize = arr.slice(0, num);
var arrSizeTwo = arr.slice(num, arr.length);
newArr.push(arrSize, arrSizeTwo);
return newArr;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey