Last active
October 6, 2015 08:39
-
-
Save VenkataRaju/3325f139d13e665aa8af to your computer and use it in GitHub Desktop.
JavaScript comparison function by operator
This file contains hidden or 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
var comparisonFunctionByOperator = (function () | |
{ | |
var hash = { | |
"<" : (left, right) => left < right, | |
"<=" : (left, right) => left <= right, | |
">" : (left, right) => left > right, | |
">=" : (left, right) => left >= right, | |
"===": (left, right) => left === right, | |
"!==": (left, right) => left !== right, | |
"==" : (left, right) => left == right, | |
"!=" : (left, right) => left != right | |
}; | |
return function (comparisonOperator) | |
{ | |
var fun = hash[comparisonOperator]; | |
if (!fun) | |
throw new Error("Invalid comparisonOperator: " + comparisonOperator); | |
return fun; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment