As the comments say, you’re tasked with creating a DSL (domain specific language).
Said in other words, a DSL is a language interpreted by your software instead of the language the software is written in.
For instance, if I had a search input, where I allow the user to type something like this: i:AlicE
; my software may interpret that as perform an insensitive search of the name of a person, where the i
represents the insensitive search. This could be implemented on my code:
// JavaScript
const people = ['Patrick', 'Dory', 'Alice'];
function doSearch(search) {
const split = search.split(':');
let foundIndex = -1;
if (split.length == 2) { // There's a 'modifier'
// For brevity, I skip the validation checks and which modifier has been
// supplied. I'm assuming it's insensitive.
// Here we search for AlicE, but as 'alice'
foundIndex = people.findIndex((i) => i.toLowerCase() == split[1].toLowerCase());
} else {
foundIndex = people.findIndex((i) => i == split[1]);
}
return foundIndex;
}
In your case, the idea is to compare the OR
, AND
and variables inside the respective arrays (the ones that start with a $
, like $State
) with the contents of the context
variable.
For example, if we take this as input:
"AND",
[
"==",
"$State",
"Alabama"
],
[
"==",
"$Profession",
"Software development"
]
Your code should evaluate it like this:
return context.State == 'Alabama' && context.Profession == 'Software development';
Of course, this is an oversimplification, since it requires you to actually parse the data.
If you’re still having problems, try searching online about how to develop a dsl to get a better understanding of it.
I hope you understand that we’re trying to guide you and not giving the answer right away .
Get back if you’re having trouble with your implementation… we may be able to help.