Jose
Jose

Reputation: 35

Is there any simple and easier away to write this javascript condition?

My condition is working, but i believe there is a more elegant and short way to write it:

  if (this.filters.provider.length !== 1) {
    return true
  } else {
    if (this.filters.provider.includes('test')) { return false }
    return true
  }

Upvotes: 2

Views: 82

Answers (2)

Abhay Kalariya
Abhay Kalariya

Reputation: 1

you can use a ternary operator like this:

return (this.filters.provider.length !== 1) ? true : this.filters.provider.includes('test') ? false : true;

Upvotes: 0

Métoule
Métoule

Reputation: 14512

return this.filters.provider.length !== 1 || !this.filters.provider.includes('test');

Upvotes: 2

Related Questions