This package groups the element of an array into sub arrays of a fixed size.
The code should run on Node v10+ without any dependencies.
In the terminal, run:
node -e "console.log(require('./index.js').groupArrayElements([1, 2, 3, 4, 5], 2));"
The output should be:
[ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]
node test.js
The package does some sanity checks on the input, throwing errors if the array argument is not an array or the size argument is not is below 1.
For other cases, like the array being empty or the the size being greater than the length of the array, then the function is more forgiving in order to provide some kind of graceful degradation.