Romaji to Kana Converter: Astro — Chapter 2, Exercise 3 ===================================================================== TASK Build convertNaiveV2 (checking lengths 1, 2, 3 in that order) and confirm it produces the correct result for "kyaku" but the wrong result ("んあ") for "na". Then explain in your own words why "n" specifically is the token that exposes this bug, when most other single-character or short tokens wouldn't. SOLUTION Running the ascending-order tokenizer for real: console.log(convertNaiveV2('kyaku')); // 'きゃく' console.log(convertNaiveV2('na')); // 'んあ' "kyaku" now works, since trying length 1 then 2 then 3 still eventually reaches length 3 and finds "kya" -- the ascending order costs nothing here, because neither "k" nor "ky" is a valid token to begin with, so the loop never stops early. "na" breaks in a genuinely different way. At position 0, length 1 is tried first: "n" IS a valid one-character token (ん) on its own. The loop matches it immediately, before ever trying length 2 ("na") at that same position. With "n" consumed, only "a" is left, which matches the vowel token directly, producing ん + あ = んあ instead of the single, correct な. The reason "n" specifically exposes this is that it's one of the only single-character tokens in the whole table that's also a genuine prefix of several longer, different tokens -- na, ni, nu, ne, no all begin with the letter n. Every other single-character token in this map is a vowel (a, i, u, e, o), and none of those are prefixes of any other token at all -- there's no "ab" or "ex" waiting to be missed the way "na" is. Most consonant-starting tokens (k, s, t, h, m, r, w) are never valid as a bare single character in the first place, so the ascending-order bug simply never gets a chance to fire on them -- there's no short, valid match to stop on early. "n" is the one genuine exception: a real, valid one-character token that also happens to sit at the front of five longer, equally real tokens. WHY THIS WORKS AS AN ANSWER ---------------------------- It verifies both real outputs, then explains the structural reason "n" is the trigger rather than treating it as an arbitrary example -- naming the specific property (a valid short token that is also a genuine prefix of longer ones) and confirming no other single- character token in the table shares that property.