If I create a function named sliceArrayIntoGroups that takes an array and a size as parameters, how can I divide the input array into smaller arrays of the specified size?
function sliceArrayIntoGroups(arr, size) {
var slicedArray = arr.slice(0, size);
return slicedArray;
}
For example, if I call this function with ["a", "b", "c", "d"] and 2 as arguments:
sliceArrayIntoGroups(["a", "b", "c", "d"], 2);
The expected output is:
[["a","b"],["c","d"]]
However, I am unsure how to store the remainder of the original array after it has been sliced.
Any assistance on this matter would be greatly appreciated.