mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Make min optional for _.clamp.
This commit is contained in:
16
lodash.js
16
lodash.js
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user