Skip to content

Instantly share code, notes, and snippets.

@FlameWolf
Created January 21, 2025 10:15
Show Gist options
  • Save FlameWolf/f3fd23eb85a279ebcbfba17ceb309834 to your computer and use it in GitHub Desktop.
Save FlameWolf/f3fd23eb85a279ebcbfba17ceb309834 to your computer and use it in GitHub Desktop.
Unicode-sensitive Palindrome Checker
const segmenter = new Intl.Segmenter();
const areStringsEqual = (first, second) => first.localeCompare(second, undefined, { sensitivity: "accent" }) === 0;
const isPalindrome = word => {
const graphemes = Array.from(segmenter.segment(word)).map(x => x.segment);
let [left, right] = [0, graphemes.length - 1];
while (left < right) {
if (!areStringsEqual(graphemes[left], graphemes[right])) {
return false;
}
left++, right--;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment