Congratulations, you made it to the end of the course! The payments team’s branch name helper now runs in JavaScript, matching the team lead’s Python. No cut splits the 😀 in Zoë’s title, the two café titles for PAY-2402 share one branch, and the Tokyo name fits the host’s 32-byte limit.
Here are the three problems again, measured with the course’s tools:
const title = "Zoë's 😀 refund fix";
console.log(title.length, [...title].length);
console.log([...title].slice(0, 7).join(""));
const typed = "cafe\u0301 receipts";
console.log(typed === "café receipts", typed.normalize() === "café receipts");
const branch = "pay-2403-東京-refund-approval";
console.log(branch.length, new TextEncoder().encode(branch).length);
Two code units make one code point, a cut by code point keeps 😀 whole, normalizing makes the two café titles equal, and the host counts 31 bytes, not 27:
19 18
Zoë's 😀
false true
27 31
In Python, len(title) gives 18, title[:7] keeps the emoji, the NFC-normalized title compares True, and len() of the encoded bytes gives 31.
In this course, you learned how to:
- Tell code units from code points and walk a string by code point with
for...ofand.codePointAt() - Compare canonically equivalent text with
.normalize()and count what a reader sees withIntl.Segmenter - Encode text to UTF-8 bytes with
TextEncoderand work withUint8Arrayviews and copies - Match Unicode with the
uandvflags, look behind and ahead, and scan with theyflag - Rebuild the team’s branch name helper in JavaScript, matching the Python version