Add _.inRange.

This commit is contained in:
Milos Zivadinovic
2015-02-14 00:23:04 +01:00
committed by jdalton
parent 540afb193b
commit f243ebba91
2 changed files with 92 additions and 4 deletions

View File

@@ -9562,6 +9562,48 @@
/*------------------------------------------------------------------------*/
/**
* Checks if `n` is between `start` and up to but not including, `end`. If
* `end` is not specified it defaults to `start` with `start` becoming `0`.
*
* @static
* @memberOf _
* @category Number
* @param {number} n The number to check.
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @returns {boolean} Returns `true` if `n` is in the range, else `false`.
* @example
*
* _.inRange(3, 2, 4);
* // => true
*
* _.inRange(4, 8);
* // => true
*
* _.inRange(4, 2);
* // => false
*
* _.inRange(2, 2);
* // => false
*
* _.inRange(1.2, 2);
* // => true
*
* _.inRange(5.2, 4);
* // => false
*/
function inRange(value, start, end) {
start = +start || 0;
if (typeof end === 'undefined') {
end = start;
start = 0;
} else {
end = +end || 0;
}
return value >= start && value < end;
}
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is provided a number between `0` and the given number is returned.
@@ -10845,8 +10887,9 @@
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to, but not including, `end`. If `start` is less than `end` a
* zero-length range is created unless a negative `step` is specified.
* `start` up to, but not including, `end`. If `end` is not specified it
* defaults to `start` with `start` becoming `0`. If `start` is less than
* `end` a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
@@ -11131,6 +11174,7 @@
lodash.identity = identity;
lodash.includes = includes;
lodash.indexOf = indexOf;
lodash.inRange = inRange;
lodash.isArguments = isArguments;
lodash.isArray = isArray;
lodash.isBoolean = isBoolean;