Hello Developers, I have an array is [1,5,6,7,8,5,9,33,45,65,11,21],
I am trying to make it as like as [[1,5,6],[7,8,5],[9,33,45],[65,11,21]];
I have done by the following code but it is not working.
const pendu=(arr)=>{
const possibleLoop=arr.length/3;
let start=0;
let results=[];
let loop=3;
let count=0;
for(start; start<loop; start++){
let newArr=[x].concat(arr[start]);
results.push(newArr);
count++;
if(count % 3 === 0){
//console.log("done")
loop=loop+3;
}
if(count > arr.length){
break;
}
}
return results;
}
console.log(pendu([1,5,6,7,8,5,9,33,45,65,11,21]))
I am just got stuck here, any suggestion ?