generate.js 470 B

1234567891011121314151617181920
  1. 'use strict';
  2. var toPosInt = require('../number/to-pos-integer')
  3. , value = require('../object/valid-value')
  4. , slice = Array.prototype.slice;
  5. module.exports = function (length/*, …fill*/) {
  6. var arr, l;
  7. length = toPosInt(value(length));
  8. if (length === 0) return [];
  9. arr = (arguments.length < 2) ? [undefined] :
  10. slice.call(arguments, 1, 1 + length);
  11. while ((l = arr.length) < length) {
  12. arr = arr.concat(arr.slice(0, length - l));
  13. }
  14. return arr;
  15. };