Help needed with JSON file

Hey guys, Please if someone can help me with this, What does it mean exactly, it is a json file, and i need to evaluate it with a function, and given context, but not familiar with this syntax.
Here is the link to task: https://repl.it/repls/HandyAliceblueLanservers

[
  "OR",
  [
    "AND",
    [
      "==",
      "$State",
      "Alabama"
    ],
    [
      "==",
      "$Profession",
      "Software development"
    ]
  ],
  [
    "OR",
    [
      "==",
      "$State",
      "Texas"
    ]
  ],
  [
    "AND",
    [
      "==",
      "$Profession",
      "Tradesperson"
    ]
  ]
]

Hello!

What is this? You’ve created a challenge or are you asking for help? Please, provide more context :slight_smile:.

I have added context to the problem. :wink:

this is an array of arrays,

more than that, like the data included and what to do with it, we can’t help with as you have not said anything about that

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 :slight_smile:.

Get back if you’re having trouble with your implementation… we may be able to help.