shim.js 753 B

12345678910111213141516171819202122232425
  1. // Taken from: https://github.com/paulmillr/es6-shim/
  2. "use strict";
  3. var toInteger = require("../../../number/to-integer")
  4. , toPosInt = require("../../../number/to-pos-integer")
  5. , validValue = require("../../../object/valid-value")
  6. , max = Math.max
  7. , min = Math.min;
  8. module.exports = function (value /*, start, end*/) {
  9. var arr = validValue(this)
  10. , start = arguments[1]
  11. , end = arguments[2]
  12. , length = toPosInt(arr.length)
  13. , relativeStart
  14. , i;
  15. start = start === undefined ? 0 : toInteger(start);
  16. end = end === undefined ? length : toInteger(end);
  17. relativeStart = start < 0 ? max(length + start, 0) : min(start, length);
  18. for (i = relativeStart; i < length && i < end; ++i) arr[i] = value;
  19. return arr;
  20. };