Tell us what’s happening:
Hello. please I don’t understand the solutions for the chunky monkey exercise. I find it difficult to connect the workings of the loop and the slice. I hope someone is willing to explain. thanks
ps ignore the comments I made in the code, doesn’t make sense.
the code I have was after checking the solutions but I still don’t get how it works.
- List item
i
Your code so far
function chunkArrayInGroups(arr, size) {
const newAr = []
{
for(let i=0;i<arr.length;i+=size){
newAr.push(arr.slice(i,i+size))
}
}
return newAr;
}
console.log(chunkArrayInGroups(["a", "b", "c", "d"], 2));
// create an emplty array
//loop through arr. regular ffor loop
// create a new empty array
//push the numbers from arr into the new empty array
//based of the size
//push the ne empty array tptonew arr
// return new arr
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Chunky Monkey
Link to the challenge: