is there a JavaScript operator that will check proximity, kind of like a soft equals? For example, instead of if (a == b)
it would read if (a is within 5 of b)
. There is probably no such thing but it would be a big help if there was.
thank you
Asked
Active
Viewed 79 times
1

puk
- 16,318
- 29
- 119
- 199

QuinnFreedman
- 2,242
- 2
- 25
- 42
3 Answers
3
There's no built-in way to do this, but you can easily accomplish the same with this:
if ( Math.abs(a - b) <= 5 )

Joseph Silber
- 214,931
- 59
- 362
- 292
1
nope, there's no such operator.
FYI, all operators can be found at https://developer.mozilla.org/en/JavaScript/Reference/Operators

qiao
- 17,941
- 6
- 57
- 46