There are two functions
const clamp = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
const map = (x, a, b, c, d, clamp) => (x - a) * (d - c) / (b - a) + c
const c = map(-50, 0, 1, 0, 100)
const _c = clamp(c, 0, 1)
console.log(_c, c)
Is there any way that the two function could be combined, something like
const _c = map(-50, 0, 1, 0, 100, {clamp: true})
so that I don’t need copy parameters from the map function to get the new value within the parameters range.