Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Created February 23, 2015 01:07
Show Gist options
  • Select an option

  • Save TechplexEngineer/44fc8e2006edc1c0b38a to your computer and use it in GitHub Desktop.

Select an option

Save TechplexEngineer/44fc8e2006edc1c0b38a to your computer and use it in GitHub Desktop.
constrain a number between an upper and lower bound
/**
* constrain a number between an upper and lower bound
* @param {num} min lower bound
* @param {num} value value to be constrained
* @param {num} max upper bound
* @return {num} the constrained value
*/
function constrain(min, value, max) {
if (value > max)
return max;
else if (value < min)
return min;
else
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment