Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getLongestLookup.js

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

  var p = adventurejs.Game.prototype;

  /**
   * Get the longest word count in the lookup table.
   * Used for iterating through lookup table from longest
   * to shortest.
   * @method adventurejs.Game#getLongestLookup
   * @memberOf adventurejs.Game
   */
  p.getLongestLookup = function Game_getLongestLookup() {
    var lookupKeys = Object.keys(this.game.world_lookup);
    var maxwords = 0;

    // figure the longest word count
    for (var l = 0; l < lookupKeys.length; l++) {
      var length = lookupKeys[l].split(" ").length;
      if (length > maxwords) {
        maxwords = length;
      }
    }
    this.game.longest_lookup = maxwords;
  };
})();