# Chunky Monkey (under Basic Algorithm Scripting) question

Chunky Monkey (under Basic Algorithm Scripting) question
0
#21

@rmdawson71 I see your point. It definitely make sense.

0 Likes

#22

Can you explain to me how this works? I was struggling with this exercise for a while.

what does βiβ represent in the for loop?

0 Likes

#23

The variable i represents the index of the array.

1 Like

#24

I donβt think this can work because every time you push a subArray, it splices it at 0, so it always slices from the beginning of the array.

0 Likes

#25

can someone tell me what is wrong with this code?

///
function chunkArrayInGroups(arr, size) {
var array = [];
var len = arr.length;

for (i = 0; i < len/size; i++){

``````array.push(arr.slice(0, size));
``````

}

// Break it up.
return array;
}

chunkArrayInGroups([βaβ, βbβ, βcβ, βdβ], 2);

0 Likes

#26

snap! aside from variable names this is exactly how I wrote my version. I started out using a Do β¦ While, it took ages and never worked, and then, as if by magic, I just threw the For Loop together and FINALLY passed the challenge, yippee!
p.s. your var names are better, I had iStart, iEnd and arrRes[], thanks for the tip.

1 Like

#27
``````  let newArr = [];
while ( arr.length > 0 ) {
let subArr = arr.slice(0,size);
arr.splice(0,size);
newArr.push(subArr);
}
console.log(newArr);
return newArr;
``````
0 Likes

closed #28
0 Likes