split.js 407 B

12345678910111213
  1. 'use strict';
  2. module.exports = function split(numberOfGroups) {
  3. var itemsPerGroup = Math.round(this.items.length / numberOfGroups);
  4. var items = JSON.parse(JSON.stringify(this.items));
  5. var collection = [];
  6. for (var iterator = 0; iterator < numberOfGroups; iterator += 1) {
  7. collection.push(new this.constructor(items.splice(0, itemsPerGroup)));
  8. }
  9. return new this.constructor(collection);
  10. };