Created
February 23, 2015 01:07
-
-
Save TechplexEngineer/44fc8e2006edc1c0b38a to your computer and use it in GitHub Desktop.
constrain a number between an upper and lower bound
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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