Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
// findMatchIn.js

(function () {
  /* global AdventureJS A */

  var p = AdventureJS.Parser.prototype;

  /**
   * Used by noun disambiguation in handleWord.js,
   * typically in cases where user has been asked a question like
   * "Which thing do you want, 1) A or 2) B ?",
   * to compare this turn's input against last turn's input.
   * @memberOf AdventureJS.Parser
   * @method AdventureJS.Parser#findMatchIn
   * @param {Object} newQualified
   * @param {Object} oldQualified
   * @returns {Object} foundMatch
   */
  p.findMatchIn = function Parser_findMatchIn(newQualified, oldQualified) {
    if (!newQualified || !oldQualified) return false;
    let foundMatch;
    for (let i = 0; i < newQualified.length; i++) {
      // 2023.04.08 in cases of substance:water:in:bowl we only want to compare "bowl"
      const nq = newQualified[i].includes(":")
        ? newQualified[i].split(":")[3]
        : newQualified[i];

      for (let j = 0; j < oldQualified.length; j++) {
        // 2023.04.08 in cases of substance:water:in:bowl we only want to compare "bowl"
        const oq = oldQualified[j].includes(":")
          ? oldQualified[j].split(":")[3]
          : oldQualified[j];

        console.warn({ nq, oq });
        if (nq === oq) {
          foundMatch = nq;
          break;
        }
        if ("undefined" !== typeof foundMatch) break;
      }
    }
    return foundMatch;
  };
})();