I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
Grey, thank you for taking your time to read through. Here is how the first code works
functionchunkArray(arr,limiter){// array to hold all chunks letfinalArray=[];// temporary array to hold each chunklettempArray=[];// loop through each value of the arrayfor(valueofarr){// check if the temporary array length is less than the desired size (limiter)if(tempArray.length<limiter){// add the current value to the temporary arraytempArray.push(value);}else{// if the temporary array length is equal to the desired size (limiter), add the whole of the temporary array to the final arrayfinalArray.push(tempArray);// empty the temporary arraytempArray=[];// add the current array value at which it got filled up tempArray.push(value);}}// after the whole looping, the last chunk (temporary array) will need one more loop to be able to be added to the final loop. Since that is not available, we add it at this point before returning the final arrayfinalArray.push(tempArray);returnfinalArray;}
chunkArray([1,2,3,4,5,6,7,8,9,10,11,12,13],5)
Hope you get it now?
I usually console log a value at any point of a code I don't understand. It makes it easier for me to see what is happening at each point of the code clearly
Please I don't understand how the first code works.
Grey, thank you for taking your time to read through. Here is how the first code works
Hope you get it now?
I usually
console log
a value at any point of a code I don't understand. It makes it easier for me to see what is happening at each point of the code clearlyThank you so much. It's clearer now