clamp a number to inclusive min and max intervals.
number
min
max
you can also provide a type alias for the output interval OutInterval number through the use of the generic parameter.
OutInterval
value to clamp
inclusive minimum of the interval
inclusive maximum of the interval
import { assertEquals } from "jsr:@std/assert"assertEquals(clamp(-5, -1, 10), -1)assertEquals(clamp(5, -1, 10), 5)assertEquals(clamp(15, -1, 10), 10) Copy
import { assertEquals } from "jsr:@std/assert"assertEquals(clamp(-5, -1, 10), -1)assertEquals(clamp(5, -1, 10), 5)assertEquals(clamp(15, -1, 10), 10)
clamp a
number
to inclusivemin
andmax
intervals.you can also provide a type alias for the output interval
OutInterval
number through the use of the generic parameter.