Make min optional for _.clamp.

This commit is contained in:
John-David Dalton
2015-10-21 22:10:05 -07:00
parent 3ee2a15cde
commit 14c2747e80
2 changed files with 32 additions and 17 deletions

View File

@@ -10904,7 +10904,7 @@
* @memberOf _
* @category Number
* @param {number} number The number whose value is to be limited.
* @param {number} min The minimum possible value.
* @param {number} [min] The minimum possible value.
* @param {number} max The maximum possible value.
* @returns {number} A number in the range [min, max].
* @example
@@ -10916,7 +10916,19 @@
* // => 5
*/
function clamp(number, min, max) {
return nativeMin(nativeMax(number, min), max);
if (max === undefined) {
max = min;
min = undefined;
}
if (max !== undefined) {
max = +max;
number = nativeMin(number, max === max ? max : 0);
}
if (min !== undefined) {
min = +min;
number = nativeMax(number, min === min ? min : 0);
}
return number;
}
/**