Created
July 31, 2012 18:03
-
-
Save jonathantneal/3218993 to your computer and use it in GitHub Desktop.
Math.between // returns whether a number is between two numbers
This file contains 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
Math.between = function (n1, n2, n3) { | |
return isNaN(n1) || isNaN(n2) || isNaN(n3) ? NaN : n1 >= Math.min(n2, n3) && n1 <= Math.max(n2, n3); | |
}; |
This file contains 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
Math.between=function(e,t,n){return isNaN(e)||isNaN(t)||isNaN(n)?NaN:e>=Math.min(t,n)&&e<=Math.max(t,n)} |
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
99 bytes minified + gzipped