Last active
June 30, 2022 08:07
-
-
Save myfonj/d322ff603b3ac26ed2788611afdd2c15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stringToCodePoints (string) { | |
function charToCodePoint (char) { | |
// "brute-force" | |
let codePoint = 0; | |
while (char !== String.fromCodePoint(codePoint)) { | |
// will throw for codePoint exceeding legal range | |
++codePoint; | |
} | |
return codePoint; | |
}; | |
return Array.from(string).map(charToCodePoint); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment