Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created July 31, 2012 18:03
Show Gist options
  • Save jonathantneal/3218993 to your computer and use it in GitHub Desktop.
Save jonathantneal/3218993 to your computer and use it in GitHub Desktop.
Math.between // returns whether a number is between two numbers
Math.between = function (n1, n2, n3) {
return isNaN(n1) || isNaN(n2) || isNaN(n3) ? NaN : n1 >= Math.min(n2, n3) && n1 <= Math.max(n2, n3);
};
Math.between=function(e,t,n){return isNaN(e)||isNaN(t)||isNaN(n)?NaN:e>=Math.min(t,n)&&e<=Math.max(t,n)}
@jonathantneal
Copy link
Author

99 bytes minified + gzipped

@renet
Copy link

renet commented Nov 20, 2020

This returns a boolean value. I'd rather expect a behavior similar to Math.min and Math.max for "Math.between". I made a gist for this case:

https://gist.github.com/renet/b388da0c866d1954fc8cf0b372e1fe94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment