Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

inRange.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var baseInRange = require('./_baseInRange'),
  2. toFinite = require('./toFinite'),
  3. toNumber = require('./toNumber');
  4. /**
  5. * Checks if `n` is between `start` and up to, but not including, `end`. If
  6. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  7. * If `start` is greater than `end` the params are swapped to support
  8. * negative ranges.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 3.3.0
  13. * @category Number
  14. * @param {number} number The number to check.
  15. * @param {number} [start=0] The start of the range.
  16. * @param {number} end The end of the range.
  17. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  18. * @see _.range, _.rangeRight
  19. * @example
  20. *
  21. * _.inRange(3, 2, 4);
  22. * // => true
  23. *
  24. * _.inRange(4, 8);
  25. * // => true
  26. *
  27. * _.inRange(4, 2);
  28. * // => false
  29. *
  30. * _.inRange(2, 2);
  31. * // => false
  32. *
  33. * _.inRange(1.2, 2);
  34. * // => true
  35. *
  36. * _.inRange(5.2, 4);
  37. * // => false
  38. *
  39. * _.inRange(-3, -2, -6);
  40. * // => true
  41. */
  42. function inRange(number, start, end) {
  43. start = toFinite(start);
  44. if (end === undefined) {
  45. end = start;
  46. start = 0;
  47. } else {
  48. end = toFinite(end);
  49. }
  50. number = toNumber(number);
  51. return baseInRange(number, start, end);
  52. }
  53. module.exports = inRange;