Created
April 19, 2012 20:45
-
-
Save marshall007/2424018 to your computer and use it in GitHub Desktop.
Math.limitRange function
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
| (function() { | |
| Math.limitRange = function(value, min, max) { | |
| return Math.max(Math.min(value, max), min); | |
| }; | |
| // test cases | |
| var tests = [[50, 0, 100], // 50 | |
| [-25, 5, 15], // 5 | |
| [7, 5, 15], // 7 | |
| [19, 36, 38]]; // 36 | |
| for (var i = 0; i < tests.length; i++) { | |
| console.log(Math.limitRange(tests[i][0], tests[i][1], tests[i][2])); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment