Skip to content

Instantly share code, notes, and snippets.

@bmorwood
Forked from kujon/clamp.js
Created March 14, 2014 01:28
Show Gist options
  • Save bmorwood/9540592 to your computer and use it in GitHub Desktop.
Save bmorwood/9540592 to your computer and use it in GitHub Desktop.
/**
* Clamps a number. Based on Zevan's idea: http://actionsnippet.com/?p=475
* params: val, min, max
* Author: Jakub Korzeniowski
* Agency: Softhis
* http://www.softhis.com
*/
(function(){Math.clamp=function(a,b,c){return Math.max(b,Math.min(c,a));}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment