Is it possible in javascript to convert a string to an operator?
I'm building a comparator for input in AngularJS.
function comparator(operatorString, value1, value2){
return value1 converted_operator(operatorString) value2;
}
var myVar1 = comparator("<", 12, 13);//true
var myVar2 = comparator(">=", 12, 13);//false
var myvar3 = comparator("!=" 12, 13);//true
And there are many possible combinations of operators. I could achieve that with an if else
. But I would like to know if there is any other alternative for the same.