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