personal-site/blog

View on GitHub
_includes/js/utils/chunk-array.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Returns an array with arrays of the given size.
 *
 * @param myArray {Array} Array to split
 * @param chunkSize {Integer} Size of every group
 */
const chunkArray = (myArray, chunkSize) => {
  const results = [];

  while (myArray.length) {
    results.push(myArray.splice(0, chunkSize));
  }

  return results;
};

export default chunkArray;