Add _.clamp and tests.

This commit is contained in:
Xotic750
2015-10-22 01:37:19 +02:00
committed by John-David Dalton
parent ff22efb3e2
commit b95ed73e1d
2 changed files with 97 additions and 1 deletions

View File

@@ -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;