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.

17 lines
428 B

4 years ago
  1. 'use strict';
  2. var values = require('../helpers/values');
  3. module.exports = function random() {
  4. var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  5. var items = values(this.items);
  6. var collection = new this.constructor(items).shuffle();
  7. // If not a length was specified
  8. if (length !== parseInt(length, 10)) {
  9. return collection.first();
  10. }
  11. return collection.take(length);
  12. };