main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import baseFill from './_baseFill.js';
|
---|
2 | import isIterateeCall from './_isIterateeCall.js';
|
---|
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 | export default fill;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.