Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 4x 1x 4x 4x | /**
* Ensures a value is between min and max
*
* @example
* Clamp value between 1 and 5
* ```ts
* const clampBetween1And5 = clamp(1, 5);
* const result = clampBetween1And5(8);
* console.log(result); // 5
* ```
*
* @returns `min` if `value < min`, or `max` if `value > max`, otherwise `value`
*/
export const clamp =
(min: number, max: number) =>
(value: number): number => {
return value < min ? min : value > max ? max : value;
};
|