How to write a system for sorting data by parameters so that it scales well regardless of the number of various parameters? For example, there is a conditional json-format in which data is stored:
{ "city": "Москва", "population": "12", "standart_of_living": "9.5", "per_capita_income": "50000", "trust_in_government": "9.8" } If you write code in JavaScript, you get a static loop without the ability to dynamically add / remove parameters. And if I wrote a simple static sample, I would do this:
for(let i = 0; i < json.length; i++) { if(json[i].population >= 10 && json[i].standart_of_living >= 8) $('#some_div').append("Город: " + json[i].city); } The result of the cycle would be the conclusion Город: Москва . But what if the user on the page wants to choose cities by the parameter "Trust level in government" (trust_in_government)? My code is static and I cannot dynamically add the && json[i].trust_in_government >= 9 parameter to it. Is there an algorithm that allows sorting by parameters without having to scribble through mountains of code?