I'm needing to create a dynamic validator based on a string value that's passed into a json object. So let's say you have the following string:
var required: "Homes > 0"
In this example, "Homes" is an accessible object within my function. I want to logically turn the above into:
if (this.Homes > 0) { return true; }
Thinking about this in parts:
if (this[left] > parsed[right]) { return true; }
I think you get the idea. I'm not sure if there's a way to easily extract operators without just doing a switch for every type? As in:
required: "Homes = 0" // this[Left] === 0
I'm about to do this in a very horrifying ugly string splitting way with a switch case on the operators. Was just wondering if there was a super slick way to make something like this robust.
var required = function(o) { return o.Homes > 0; };?