PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/fill.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 45 lines | 14 code | 2 blank | 29 comment | 6 complexity | 4350140e9e57cadcf074acd02f8a86fb MD5 | raw file
 1var 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 */
33function 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
45module.exports = fill;