I have a problem...
I have a string that inputted by the user and looks something like this
let conditions = "id === 101 || name === 'Albert' && age !== 43"
I also have an array of data that was also created by the user at some point previously The data was stored in the form of an array that looks like so, and the user now has requested all data entries that match the conditions he has given.
let data = [
{id:101, name:"Albert", age:63},
{id:102, name:"Einstein", age:53}
]
You can probably see where I'm going with this. The array to be returned should look like this.
let returnedArray = [
{id:101, name:"Albert", age:63}
]
Now, my first thought was just to use eval. Creating the variables with eval and for loop, checking with eval and so on.
But that would be very slow and seems redundant. Also, we can no longer declare variables with eval, and creating so many global variables would be quite harmful to my project.
Neither the conditions or the data array are static. The conditions are user inputed and the data arrays are not only ever changing, they are also user created.
Any suggestions?