• notice
  • Congratulations on the launch of the Sought Tech site

Problem with using .filter(), confused with AND/OR (&&/||), can someone help me?

I'm having trouble getting the data. so I want to filter out any that have "Draft" or of invoice_status, or"Ready to Bill", "Cancelled"if It is invoice_status is null AND status is null

Everything is properly filtered out except invoice_status is null AND status is nullNot filtered outanything.What's wrong 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)
 )
);

uj5u.com enthusiastic netizens replied:

The filter condition in the code is written as the negation (opposite) of the conditional word, so that in

font>trueWhen to retain elements.Your statement is correctly negated, except: ! invoice_status is null AND status is nullnot(r.invoice_status !==null && r.status !==null), yes(r.invoice_status !==null || r.status !==null).

This is the general rule:!(A & & B)==(!A || !B), see Negative Rules.

uj5u.com enthusiastic netizens replied:

Since you want to filterdrop invoice_status is null AND status is null, so when you reverse the logic, by De Morgan's theorem, you get invoice_status is not null OR status is not null.final change&&a||should do the trick

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+