mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add _.clamp and tests.
This commit is contained in:
committed by
John-David Dalton
parent
ff22efb3e2
commit
b95ed73e1d
24
lodash.js
24
lodash.js
@@ -10893,6 +10893,29 @@
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Returns a number whose value is limited to the given range specified
|
||||
* by `min` and `max`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Number
|
||||
* @param {number} number The number whose value is to be limited.
|
||||
* @param {number} min The minimum possible value.
|
||||
* @param {number} max The maximum possible value.
|
||||
* @returns {number} A number in the range [min, max].
|
||||
* @example
|
||||
*
|
||||
* _.clamp(-10, -5, 5);
|
||||
* // => -5
|
||||
*
|
||||
* _.clamp(10, -5, 5);
|
||||
* // => 5
|
||||
*/
|
||||
function clamp(number, min, max) {
|
||||
return nativeMin(nativeMax(number, min), max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `n` is between `start` and up to but not including, `end`. If
|
||||
* `end` is not specified it's set to `start` with `start` then set to `0`.
|
||||
@@ -12958,6 +12981,7 @@
|
||||
lodash.camelCase = camelCase;
|
||||
lodash.capitalize = capitalize;
|
||||
lodash.ceil = ceil;
|
||||
lodash.clamp = clamp;
|
||||
lodash.clone = clone;
|
||||
lodash.cloneDeep = cloneDeep;
|
||||
lodash.cloneDeepWith = cloneDeepWith;
|
||||
|
||||
Reference in New Issue
Block a user