Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active June 1, 2018 00:15
Show Gist options
  • Select an option

  • Save gladchinda/989eaec54e897fc12d424aab1464303f to your computer and use it in GitHub Desktop.

Select an option

Save gladchinda/989eaec54e897fc12d424aab1464303f to your computer and use it in GitHub Desktop.
var MIN_VALUE = 1;
var MAX_VALUE = 5;
/**
* boundedValue(val)
*
* Returns val if val between MIN_VALUE and MAX_VALUE both inclusive
*
* Otherwise, returns MIN_VALUE if val is less than MIN_VALUE
*
* Else, returns MAX_VALUE if val is greater than MAX_VALUE
*/
function boundedValue(val) {
return Math.max(MIN_VALUE, Math.min(MAX_VALUE, val));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment