Feeling discouraged (chunky monkey assignment)

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 :slight_smile:

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;
}
mainArrs.push([arr.slice(zero,size)]);

You have several lines that look similar to the above line. You have wrapped [ and ] around the result of the slice method on arr. This has the effect of pushing a two-dimensional array into mainArrs instead of a one-dimensional array into mainArrs.

EDIT: I am not sure why you have written the following lines as you did.

chunkArrayInGroups.nextStep=0;
chunkArrayInGroups.newNextStep=0;

Why not just declare two variables nextStep and newNextStep and assign 0 to both of them before the for loop?

Thank you , that solved it :slight_smile:
I was just confused about it needing to be an array of arrays.
And then I got lost in the details and thought the two variables needed to be static.