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 }