chunk.js 370 B

12345678910111213
  1. import { slice } from './_setup.js';
  2. // Chunk a single array into multiple arrays, each containing `count` or fewer
  3. // items.
  4. export default function chunk(array, count) {
  5. if (count == null || count < 1) return [];
  6. var result = [];
  7. var i = 0, length = array.length;
  8. while (i < length) {
  9. result.push(slice.call(array, i, i += count));
  10. }
  11. return result;
  12. }