Tell us what’s happening:
can someone who knows what they’re doing tell me why i shouldn’t use this code?
after i pass the tests i always look at the other possible solutions to see how i could have coded it. i usually take the NASA route in programming… but my version looked like a mashup of several answers. any tips on how to improve this would be appreciated!
Your code so far
function chunkArrayInGroups(arr, size) {
let newChunk = [];
for (var i = 0; i < arr.length;newChunk.push(arr.splice(0,size))) {
} return newChunk;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0.
You have no code in the body of the loop. I’m not sure how you ended up with that code structure. You seem to have replaced the incrementing part of the loop code with the body of the loop.
I think in this form the code would be less confusing. But, as @ILM noted below, it’s usually not a good idea to mutate the input inside your function.