Skip to content

Instantly share code, notes, and snippets.

@abozhilov
Created October 15, 2012 20:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abozhilov/3895019 to your computer and use it in GitHub Desktop.
Save abozhilov/3895019 to your computer and use it in GitHub Desktop.
Partial application Value range
function valueRange(start, end) {
return function (value) {
return Math.min(Math.max(value, start), end);
};
}
//Get new value range [0, 20]
var f = valueRange(0, 20);
console.log(f(10)); //10
console.log(f(21)); //20
console.log(f(-2)); //0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment