You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
843 B

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