Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

28 rader
850 B

4 år sedan
  1. /* Built-in method references for those with the same name as other `lodash` methods. */
  2. var nativeCeil = Math.ceil,
  3. nativeMax = Math.max;
  4. /**
  5. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  6. * coerce arguments.
  7. *
  8. * @private
  9. * @param {number} start The start of the range.
  10. * @param {number} end The end of the range.
  11. * @param {number} step The value to increment or decrement by.
  12. * @param {boolean} [fromRight] Specify iterating from right to left.
  13. * @returns {Array} Returns the range of numbers.
  14. */
  15. function baseRange(start, end, step, fromRight) {
  16. var index = -1,
  17. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  18. result = Array(length);
  19. while (length--) {
  20. result[fromRight ? length : ++index] = start;
  21. start += step;
  22. }
  23. return result;
  24. }
  25. module.exports = baseRange;