15 lines
375 B
JavaScript
15 lines
375 B
JavaScript
|
|
/**
|
||
|
|
* Clamp value.
|
||
|
|
* Detects proper clamp min/max.
|
||
|
|
*
|
||
|
|
* @param {number} a Current value to cut off
|
||
|
|
* @param {number} min One side limit
|
||
|
|
* @param {number} max Other side limit
|
||
|
|
*
|
||
|
|
* @return {number} Clamped value
|
||
|
|
*/
|
||
|
|
'use strict';
|
||
|
|
module.exports = function(a, min, max){
|
||
|
|
return max > min ? Math.max(Math.min(a,max),min) : Math.max(Math.min(a,min),max);
|
||
|
|
};
|