Basic Algorithmic Scripting: Chunky Monkey Beginner Solution Feedabck

Tell us what’s happening:

Any feedback would be highly appreciated.

  **Your code so far**

function chunkArrayInGroups(arr, size) 
 
let slicedArr = [];

for (let i = 0; i <= arr.length; i++){
    slicedArr.push(arr.splice(0, size));
}

if(arr.length >= 1) {
        slicedArr.push(arr);
    }
    else {
        return slicedArr;
    }

// console.log(slicedArr);


return slicedArr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36.

Challenge: Chunky Monkey

Link to the challenge:

I’d suggest not to use splice on the array you’re looping over (it works here, but it’s a bad habit that will bite you in the future).
Also I’d avoid mutating function parameters.
And you don’t need else statement.

1 Like