Skip to content

Instantly share code, notes, and snippets.

@adielBm
Last active August 30, 2023 13:20
Show Gist options
  • Save adielBm/89413ee1c2ee4eb5c7106b9f575d6f6b to your computer and use it in GitHub Desktop.
Save adielBm/89413ee1c2ee4eb5c7106b9f575d6f6b to your computer and use it in GitHub Desktop.
arabicToHebrew
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