$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #118

Which fix handles the text correctly?

const first = 'e\u0301'.charAt(0);
console.log('🙂'.length);
  1. Iterate code points: [...str] instead
  2. Iterate code points: str.split('') instead
  3. Call normalize() after taking charAt
  4. Compare with charCodeAt(0) instead
length and charAt count UTF-16 units, so an emoji counts as 2; spreading walks code points.
Play Problem Solving ▸