Skip to content

Instantly share code, notes, and snippets.

@WillSquire
Created July 2, 2015 14:36
Show Gist options
  • Save WillSquire/c8187e511a8b2220b701 to your computer and use it in GitHub Desktop.
Save WillSquire/c8187e511a8b2220b701 to your computer and use it in GitHub Desktop.
Clamp - Clamps a value to within the min or max values given.
/**
* Clamps a value to within the min or max values given.
*
* @param {number} value
* @param {number} min
* @param {number} max
* @returns {number}
*/
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment