generate.js 504 B

123456789101112131415161718
  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, currentLength;
  7. length = toPosInt(value(length));
  8. if (length === 0) return [];
  9. arr = arguments.length < 2 ? [undefined] : slice.call(arguments, 1, 1 + length);
  10. while ((currentLength = arr.length) < length) {
  11. arr = arr.concat(arr.slice(0, length - currentLength));
  12. }
  13. return arr;
  14. };