Last active
August 30, 2023 13:20
-
-
Save adielBm/89413ee1c2ee4eb5c7106b9f575d6f6b to your computer and use it in GitHub Desktop.
arabicToHebrew
This file contains 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 YOUR_TEXT = "كتاب العين للخليل بن أحمد الفراهيدي" | |
function arabicToHebrew(str) { | |
const mapping = { | |
"ا": "א", | |
"ب": "ב", | |
"ج": "ג'", | |
"د": "ד", | |
"ذ": "ד'", | |
"ه": "ה", | |
"و": "ו", | |
"ز": "ז", | |
"ح": "ח", | |
"خ": "ח'", | |
"ط": "ט", | |
"ظ": "ט'", | |
"ي": "י", | |
"ك": "כ", | |
"ل": "ל", | |
"م": "מ", | |
"ن": "נ", | |
"س": "ס", | |
"ع": "ע", | |
"غ": "ע'", | |
"ف": "פ", | |
"ص": "צ", | |
"ض": "צ'", | |
"ق": "ק", | |
"ر": "ר", | |
"ش": "ש", | |
"ت": "ת", | |
"ث": "ת'", | |
}; | |
let result = ""; | |
let i = 0; | |
const strLength = str.length; | |
while (i < strLength) { | |
let foundReplacement = false; | |
// Check for multi-character replacements | |
for (const key in mapping) { | |
if (str.startsWith(key, i)) { | |
result += mapping[key]; | |
i += key.length; | |
foundReplacement = true; | |
break; | |
} | |
} | |
if (!foundReplacement) { | |
result += str[i]; | |
i++; | |
} | |
} | |
return result; | |
} | |
console.log(arabicToHebrew(YOUR_TEXT)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment