[+] Encapsulate minmax

This commit is contained in:
Hykilpikonna
2021-12-11 17:16:13 -05:00
parent a959b32192
commit 0b5e25e996
+12
View File
@@ -20,3 +20,15 @@ export function range(fromOrTo: number, to?: number, step = 1): number[]
return [...Array(Math.floor((Math.abs(to - from)) / step))].map((_, i) => from + i * step * mul);
}
/**
* Make sure that the value is between a min and a max
*
* @param val
* @param min
* @param max
*/
export function minMax(val: number, min: number, max: number): number
{
return val > max ? max : val < min ? min: val
}