25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
843 B

4 년 전
  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;