- Home /
Is there a JavaScript "Between X and Y values" Operator?
Simple ennought,
Is there a operator to check if a value is "Between" two values?
Example.
if(Z is between X and Y ))
Answer by oron75 · Dec 28, 2011 at 03:07 PM
other way is to use the property method for any type of var (Number, String, Date ,etc) As Follow:
var between = function(a,b){ if(a>b) return this>=b && this<=a else return this>=a && this<=b } Number.prototype.between = between; String.prototype.between = between; Date.prototype.between = between; ja = 5 jb = 2 jt = 3 alert(jt.between(ja,jb)) alert((1).between(ja,jb)) alert("c".between("e","d"))
Your answer
Follow this Question
Related Questions
"someValue = anotherValue > 0.1" What does this mean? 3 Answers
How is this operator in a variable declaration? 1 Answer
C# Error help ( error CS0023 The `!’ operator cannot be applied to operand of type `string’ ) ??? 1 Answer
Why does the added char always stay at the end of my string ? (Operator "+=") 2 Answers