baseFill.js 799 B

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