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