_array-fill.js 643 B

123456789101112131415
  1. // 22.1.3.6 Array.prototype.fill(value, start = 0, end = this.length)
  2. 'use strict';
  3. var toObject = require('./_to-object');
  4. var toAbsoluteIndex = require('./_to-absolute-index');
  5. var toLength = require('./_to-length');
  6. module.exports = function fill(value /* , start = 0, end = @length */) {
  7. var O = toObject(this);
  8. var length = toLength(O.length);
  9. var aLen = arguments.length;
  10. var index = toAbsoluteIndex(aLen > 1 ? arguments[1] : undefined, length);
  11. var end = aLen > 2 ? arguments[2] : undefined;
  12. var endPos = end === undefined ? length : toAbsoluteIndex(end, length);
  13. while (endPos > index) O[index++] = value;
  14. return O;
  15. };