import _ from 'lodash';

class ChallengeTitles {
  constructor() {
    this.knownTitles = [];
  }
  check(title) {
    if (typeof title !== 'string') {
      throw new Error(`Expected a valid string for ${title}, got ${typeof title}`);
    } else if (title.length === 0) {
      throw new Error(`Expected a title length greater than 0`);
    }
    const titleToCheck = title.toLowerCase().replace(/\s+/g, '');
    const titleIndex = _.findIndex(this.knownTitles, existing => titleToCheck === existing);
    if (titleIndex !== -1) {
      throw new Error(`
    All challenges must have a unique title.

    The title ${title} is already assigned
    `);
    }
    this.knownTitles = [ ...this.knownTitles, titleToCheck ];
  }
}

export default ChallengeTitles;

@@ -210,11 +210,20 @@
 e%7D, 
-got
+but got a(n)
  $%7Bt
@@ -426,116 +426,74 @@
 nst 
-titleIndex = _.findIndex(this.knownTitles, existing =%3E titleToCheck === existing);%0A    if (titleIndex !== -1
+isKnown = this.knownTitles.includes(titleToCheck);%0A    if (isKnown
 ) %7B%0A

Simplify Unique Titles Test (#17056)