mercredi 18 septembre 2019

Using two for loops to find duplicates

This is my function to enable button if conditions are met and function return true. I've added additional for loop to find duplicates and now it doesn't work right. Please advise where did I make a mistake?

 enabled(): boolean {
    for (let i: number = 0; i < this.entries.length; ++i) {
      let strText: string = this.entries[i].textN;
      let strValue: number = this.entries[i].valueN;

      if (strText.includes('=') || strText.includes(',')) {
        return false;
      }

      if (strText == null || strText == undefined || strText == '') {
        return false;
      }

      if (!strValue || strValue % 1 !== 0) {
        return false;
      }

      for (let j = i + 1; j < this.entries.length; ++j) {
        if (strValue[i] === strValue[j]) {
          return false;
        }
      }
    }

    return true;
  }

Aucun commentaire:

Enregistrer un commentaire