Last active
October 29, 2024 17:37
-
-
Save Kimtaro/129548da67bbfa9b44a286931b0fc466 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
const HIRAGANA = "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ"; | |
const KATAKANA = "ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ"; | |
function transliterateHiraganaToKatakana(text) { | |
var newText = ""; | |
for(let character of text) { | |
const codepoint = character.codePointAt(0); | |
if(codepoint >= 12353 && codepoint <= 12438) { | |
newText = newText + String.fromCodePoint(codepoint + 96); | |
} | |
else { | |
newText = newText + character; | |
} | |
} | |
return newText; | |
} | |
if(transliterateHiraganaToKatakana(HIRAGANA) === KATAKANA) { | |
console.log("Conversion successful"); | |
} | |
if(transliterateHiraganaToKatakana("Latin text") === "Latin text") { | |
console.log("Conversion successful"); | |
} | |
if(transliterateHiraganaToKatakana("Mixedあア") === "Mixedアア") { | |
console.log("Conversion successful"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment