how to divide array in chunks

Solutions on MaxInterview for how to divide array in chunks by the best coders in the world

showing results for - "how to divide array in chunks"
Maria
16 Jan 2016
1function chunkArray(arr,n){
2     var chunkLength = Math.max(arr.length/n ,1);
3     var chunks = [];
4     for (var i = 0; i < n; i++) {
5         if(chunkLength*(i+1)<=arr.length)chunks.push(arr.slice(chunkLength*i, chunkLength*(i+1)));
6     }
7     return chunks; 
8 }
queries leading to this page
divide an array in two in jshow to divide array into chunksjs divide array into twodivide array into part jsjavascript divide array into threehow to divide array in two equal parts in javascriptjavascript divide array into equal parts slice divide an array into four eqaul arrays jsjs how to divide 2 arraysdivide an array into k parts javascriptjavascript divide array into two equal partshow to divide array in two parts javascriptjavascript divide array number by 2divide array into two by index javascriptjs divide array into 2 halves using splithow to divide array in two parts jsdivide array into k parts javascripthow to divide array in two parts usin jsdivide array in two parts javascriptdivide one array in two according to an element javascriptdivide array into two parts javascriptdivide array into 2 jswrite a program to divide an array into 2 parts jsdivide array into equal parts javascriptdivide array in chunks javascriptdivide array in to two part si jshow to divide an array into n parts javascriptdivide array into 2 parts jsjavascript divide array into equal partsdivide each element in array by 2 javascriptdivide an array with length javascriptdivide array into two parts jshow to divide an array into two parts in javascriptjavascript divide array into partsdivide the numbers of two array javascripthow to divide arrays in two parts in javascripthow to divide array in two parts in jshow to divide array elements jsdivide array in multiple array 3 elements javascriptdivide list in two parts javascriptdivide array into 4 parts javascriptjavascript divide array into twodivide 2 arrays javascriptdivide array into three equal parts jsjs divide an array in 2 partsdivide array into more arraydivide array into two equal parts javascripthow to divide array in two parts in javascriptdivide array in two jshow to divide an array in 2 in jsdivide array into k parts jshow to divide 2 array in jshow to divide an array in multiple equal parts in jshow to divide large array in two parts javascript divide array into 4 equal parts javascriptdivide array by n in jshow to add and divide array in javascriptjavascript divide array by 4how to divide array in chunks