1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 19:04:46 +00:00

refactor(packages/stdlib): add comments for math utils

This commit is contained in:
2024-04-11 00:10:52 +07:00
parent e9b8b0c78d
commit 65ba312f4c
2 changed files with 11 additions and 1 deletions

View File

@@ -7,5 +7,10 @@
* @returns {number} The clamped number
*/
export function clamp(value: number, min: number, max: number): number {
// The clamp function takes a value, a minimum, and a maximum as parameters.
// It ensures that the value falls within the range defined by the minimum and maximum values.
// If the value is less than the minimum, it returns the minimum value.
// If the value is greater than the maximum, it returns the maximum value.
// Otherwise, it returns the original value.
return Math.min(Math.max(value, min), max);
}