Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda