So I have used splice to remove what I need and return the rest of the numbers in the array beside it. My issue is chunking those arrays to the size variable. Do I have to use slice? Can I just keep using splice? And I have no idea where to implement the loop at, what exactly would I be looping over and can I use splice instead of slice in conjunction with it? I have asked question on many challenges in this section, but I want to learn instead of just reading the methods on how to chunk an array (which is exactly this challenge) online. Thanks!
function chunkArrayInGroups(arr, size) {
let newArr=[]
let result=0;
for (let i=0;i<arr.length;i++) {
result=arr.splice(0,size)
newArr.push(result)
}
return newArr
}
console.log(chunkArrayInGroups(["a", "b", "c", "d"], 2));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Chunky Monkey
Link to the challenge: