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

316
Vistas
Issue with using .filter(), confused with the AND/OR (&&/||), could someone help me out?

I am having an issue here with getting my data. So I want to filter out any that has an invoice_status of "Draft" or "Ready to Bill", or "Cancelled" or if it's invoice_status is null AND status is null

Everything is being filtered out correctly except any data that has both invoice_status is null AND status is null is not being filtered out. What is the issue with my code below?

console.log(
  "data...",
  this.props.partnerOrders.filter(
    r =>
      (r.invoice_status !== "Draft" &&
      r.invoice_status !== "Ready to Bill" &&
      r.invoice_status !== "Cancelled") || 
      (r.invoice_status !== null && r.status !== null)
  )
);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your filter condition in the code is written as the negation (opposite) of your condition-as-words, so as to be true when the element should be kept. Your statement is correctly negated except: !invoice_status is null AND status is null is not (r.invoice_status !== null && r.status !== null), it is (r.invoice_status !== null || r.status !== null).

This is a general rule: !(A && B) == (!A || !B), see rules of negation.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you want to filter out invoice_status is null AND status is null, when you invert the logic, by deMorgan's theorem, you get invoice_status is not null OR status is not null. Changing your final && to an || should do the trick

about 4 years ago · Juan Pablo Isaza Denunciar
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