Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | var baseFill = require('./_baseFill'),
|
---|
2 | isIterateeCall = require('./_isIterateeCall');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Fills elements of `array` with `value` from `start` up to, but not
|
---|
6 | * including, `end`.
|
---|
7 | *
|
---|
8 | * **Note:** This method mutates `array`.
|
---|
9 | *
|
---|
10 | * @static
|
---|
11 | * @memberOf _
|
---|
12 | * @since 3.2.0
|
---|
13 | * @category Array
|
---|
14 | * @param {Array} array The array to fill.
|
---|
15 | * @param {*} value The value to fill `array` with.
|
---|
16 | * @param {number} [start=0] The start position.
|
---|
17 | * @param {number} [end=array.length] The end position.
|
---|
18 | * @returns {Array} Returns `array`.
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * var array = [1, 2, 3];
|
---|
22 | *
|
---|
23 | * _.fill(array, 'a');
|
---|
24 | * console.log(array);
|
---|
25 | * // => ['a', 'a', 'a']
|
---|
26 | *
|
---|
27 | * _.fill(Array(3), 2);
|
---|
28 | * // => [2, 2, 2]
|
---|
29 | *
|
---|
30 | * _.fill([4, 6, 8, 10], '*', 1, 3);
|
---|
31 | * // => [4, '*', '*', 10]
|
---|
32 | */
|
---|
33 | function fill(array, value, start, end) {
|
---|
34 | var length = array == null ? 0 : array.length;
|
---|
35 | if (!length) {
|
---|
36 | return [];
|
---|
37 | }
|
---|
38 | if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
---|
39 | start = 0;
|
---|
40 | end = length;
|
---|
41 | }
|
---|
42 | return baseFill(array, value, start, end);
|
---|
43 | }
|
---|
44 |
|
---|
45 | module.exports = fill;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.