I don’t understand what I am doing wrong. Why does it skip ‘dog’ for example?
I really need som hints!!
thanks
Your code so far
function chunkArrayInGroups(array, num) {
for (var i = 0; i <= array.length; i++) {
console.log(array[i])
var spliced = array.splice(i, num);
console.log(spliced);
}
let bigArr = [spliced];
return bigArr;
}
let array = ['cat', 'banana', 'dog', 'mustard', 'lion'];
let num = 2;
console.log(chunkArrayInGroups(array, num))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0
Challenge Information:
Implement the Chunky Monkey Algorithm - Implement the Chunky Monkey Algorithm
It’s never a good idea to change the contents of an array you are looping over. And do you really want the loop variable to ever be equal to the array length?