Remove repetition of code due to if condition

  Kiến thức lập trình

I have below code in my ts file.**

    const modNames = ['CW652', 'MNOP200', '100ABCD', 'XYZ200'];
    if (model && modNames.includes(model) && !this.installed && !isActive) {
      this.route = true;
      this.stop = false;
    } else if (model && !modNames.includes(model) && this.installed && !isActive) {
      this.route = true;
      this.stop = false;
    } else {
      this.route = false;
      this.stop = true;
    }

My business logic inside first two if conditions is same. Is it possible to combine first two if in one?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT