You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
408 B

4 years ago
  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. };