_array-fill.js 610 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. , toIndex = require('./_to-index')
  5. , toLength = require('./_to-length');
  6. module.exports = function fill(value /*, start = 0, end = @length */){
  7. var O = toObject(this)
  8. , length = toLength(O.length)
  9. , aLen = arguments.length
  10. , index = toIndex(aLen > 1 ? arguments[1] : undefined, length)
  11. , end = aLen > 2 ? arguments[2] : undefined
  12. , endPos = end === undefined ? length : toIndex(end, length);
  13. while(endPos > index)O[index++] = value;
  14. return O;
  15. };