Skip to content

constrain

Subhajit Sahu edited this page Aug 9, 2022 · 2 revisions

Constrain a number within a minimum and a maximum value.

Similar: constrain, normalize, remap, lerp.


function constrain(x, min, max)
// x:   a number
// min: minimum value
// max: maximum value

const xnumber = require('extra-number');


xnumber.constrain(20, 0, 50);
// → 20

xnumber.constrain(-10, 0, 100);
// → 0

xnumber.constrain(120, 0, 100);
// → 100


References

Clone this wiki locally