1
|
var toInteger = require('./toInteger'),
|
2
|
toLength = require('./toLength');
|
3
|
|
4
|
/**
|
5
|
* The base implementation of `_.fill` without an iteratee call guard.
|
6
|
*
|
7
|
* @private
|
8
|
* @param {Array} array The array to fill.
|
9
|
* @param {*} value The value to fill `array` with.
|
10
|
* @param {number} [start=0] The start position.
|
11
|
* @param {number} [end=array.length] The end position.
|
12
|
* @returns {Array} Returns `array`.
|
13
|
*/
|
14
|
function baseFill(array, value, start, end) {
|
15
|
var length = array.length;
|
16
|
|
17
|
start = toInteger(start);
|
18
|
if (start < 0) {
|
19
|
start = -start > length ? 0 : (length + start);
|
20
|
}
|
21
|
end = (end === undefined || end > length) ? length : toInteger(end);
|
22
|
if (end < 0) {
|
23
|
end += length;
|
24
|
}
|
25
|
end = start > end ? 0 : toLength(end);
|
26
|
while (start < end) {
|
27
|
array[start++] = value;
|
28
|
}
|
29
|
return array;
|
30
|
}
|
31
|
|
32
|
module.exports = baseFill;
|