Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Optimization of a set of exclusive filters

Hi recently I was asked a very interesting question: Giving a set of Data

data = [{name: "gem1", year: 2013, color:"yellow"}, {name: "gem2", year: 2013, color:"blue"}, {name: "gem3", year: 2021, color:"blue"}]

And a set of Filter

filters = [{k: "color", v: "yellow"}]

Show the data excluded by filter like:

getExclusive(data, filters) = [{name: "gem2", year: 2013, color:"blue"}, {name: "gem3", year: 2021, color:"blue"}]

Also the additional is that, question itself has mentioned that a very raw method:

filter.forEach(filter => {data = data.filter(datum => {return datum[filter.k] == filter.v})})

Is TOO SLOW. And the purpose is to optimize it.

Keep in mind that each object in data will have unknown number of keys, and the key names are also dynamic, for example: obj1 can only have {lastName: "last", firstName: "first"} and obj2 can only have {model: "Jeep", year: 2021, color: "white"})

I thought the reason why it's slow is because the big O goes to F * D.

And I want to convert the filters to a Map<string, Set> so that for every data it will look the location in O(1).

But then I found I was wrong. Because in this way it needs to go through every key in each obj to see if it hits a filter. Therefore it becomes F + D * <avg key numbers in data>, which might be even worse if key number is so large?

So is there any other way to optimize it absolutely, or maybe this is just an open question with no definite answer?

Note that this question is in JavaScript. So I don't know if any internal APIs would be considered

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!