Hi All,
I’m trying to solve the problem as below
function chunkArrayInGroups(arr, size) {
// Break it up.
let arr2 = [];
let multiDimensionalArryElementsCount = arr.length / size;
if(arr.length % size != 0){
multiDimensionalArryElementsCount++;
}
let arraySize = 0;
for(let count = 0; count < size; count++){
for(let count2 = 0; count2 < multiDimensionalArryElementsCount; count2++ ){
if( arraySize < arr.length){
arr2[count] = new Array(multiDimensionalArryElementsCount);
arr2[count][count2] = arr[arraySize];
arraySize++;
}else{
break
}
}
}
return arr2;
}
console.log( chunkArrayInGroups(["a", "b", "c", "d"], 2) );
When the result prints out, first element of each of the multi dimensional array is undefined. While debugging I’ve seen value is properly getting inserted at right place.
Please review code, as I’m not getting what’s going wrong
Thanks in advance.
Regards,
Vikram