Hi, I manage to complete this challenge but I didn’t manage to use the array.push() method. I have included my code below :
/** setup
function chunkArrayInGroups(arr, size) {
// Break it up.
var totalArr = [];
if (arr.length/size <= 2) {
firstArr= arr.splice (0, size);
secondArr= arr;
totalArr = [firstArr, secondArr];
}
else if (arr.length/size <= 3) {
firstArr= arr.splice (0, size);
secondArr= arr.splice (0,size);
thirdArr = arr;
totalArr = [firstArr, secondArr, thirdArr]; }
else if (arr.length/size <= 4) {
firstArr= arr.splice (0, size);
secondArr= arr.splice (0,size);
thirdArr = arr.splice(0,size);
fourthArr= arr;
totalArr = [firstArr, secondArr, thirdArr, arr]; }
return totalArr;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
**/ end setup
I feel like my code is not complete because if chunkArrayInGroups ([0, 1, 2, 3, 4, 5], 1), the result is only [].
Can anyone push me to the right direction to produce a better code for this challenge?
Many thanks in advance