I am working through a javascript problem that asks me to:
Write a function that splits an array (first argument) into groups the length of size (second argument) an
function chunk(arr, size) {
var newArr = []; // New empty array
while (arr.length > 0) { // Loop thru the array items
newArr.push(arr.splice(0, size)); // Removes first 2 items then add it to new array
}
return newArr; // New 2D array
}
I tried using these lines of codes in console and it worked perfectly fine.