chunk.js 387 B

12345678910111213141516
  1. var _setup = require('./_setup.js');
  2. // Chunk a single array into multiple arrays, each containing `count` or fewer
  3. // items.
  4. 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(_setup.slice.call(array, i, i += count));
  10. }
  11. return result;
  12. }
  13. module.exports = chunk;