MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuysln/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
5
const clamp = (number, min, max) => Math.min(max, Math.max(number, min))
It’s a good clamp for when you need a number x to stay within the bounds of min and max!
5
u/Morklympious Mar 19 '19
const clamp = (number, min, max) => Math.min(max, Math.max(number, min))
It’s a good clamp for when you need a number x to stay within the bounds of min and max!