Hi all ,
I think I spend two days trying to figure this assignment out on my own.
It seems to work and correctly seperate the arr array into smaller arrays (when I add document.write statements ), but the code is not passing.
I can look at the hints or solutions , but that doesn’t really help me figure out why my code is wrong.
I hope someone is willing to take a look at it ,it’s a bit longer.
Thanks
function chunkArrayInGroups(arr, size) {
/*Write a function that splits an array (first argument) into groups
the length of size (second argument) and returns them as a two-dimensional array.*/
let len = arr.length;
let numberOfArrs = len/size;
let zero =0;
let mainArrs = new Array();
chunkArrayInGroups.nextStep=0;
chunkArrayInGroups.newNextStep=0;
for(let i=zero;i<numberOfArrs;++i){
if(numberOfArrs === 2){
if(i === zero){
mainArrs.push([arr.slice(zero,size)]);
}else{
mainArrs.push([arr.slice(size,len)]);
}
} else {
if(i === zero){
mainArrs.push([arr.slice(zero,size)]);
} else if(i===1){
nextStep = size*2 ;
mainArrs.push([ arr.slice(size,nextStep)]);
} else {
newNextStep= nextStep+size;
mainArrs.push([arr.slice(nextStep,newNextStep)]);
nextStep=newNextStep;
}
}
}
return mainArrs;
}