Ramda clamp

6/4/2020
#til, #ramda

Today I learned that Ramda has a clamp function. What is clamp? It allows you to set value between min & max.

Example:

import { clamp } from 'ramda';

setCoordinates(clamp(-90, 90, event.target.value));

Value will be set to at max 90 or at min -90 or everything in between.

You can do it without ramda via:

const coordinateValue = Math.min(Math.max(parseInt(number), -90), 90);
setCoordinates(coordinateValue);

Taken from How can I use JavaScript to limit a number between a min/max value? - Stack Overflow.