Examples > text-adventures COMPANION ZMACHINE.JS (13/28) const max = this.mem[parseAddr]; const n = Math.min(words.length, max); this.mem[parseAddr + 1] = n; const keyLen = v <= 3 ? 4 : 6; for (let w = 0; w < n; w++) { const { pos, len: wl } = words[w]; const key = this.encodeWord(this.mem.subarray(start + pos, start + pos + wl)); const found = this.lookup(entries, entryLen, count, key, keyLen); const e = parseAddr + 2 + 4 * w; if (skipUnknown && !found) continue; this.ww(e, found); this.mem[e + 2] = wl; this.mem[e + 3] = pos + (start - textAddr); } } lookup(entries, entryLen, count, key, keyLen) { const cmp = (addr) => { for (let k = 0; k < keyLen; k++) { const diff = this.mem[addr + k] - key[k]; if (diff) return diff; } return 0; }; if (count > 0) { let lo = 0, hi = count - 1; while (lo <= hi) { const mid = (lo + hi) >> 1; const addr = entries + mid * entryLen; const c = cmp(addr); if (c === 0) return addr; if (c < 0) lo = mid + 1; else hi = mid - 1; } return 0; } for (let i = 0; i < -count; i++) { const addr = entries + i * entryLen; if (cmp(addr) === 0) return addr; } return 0; } Next: 35 Companion zmachine.js (14/28)