Skip to content

Instantly share code, notes, and snippets.

@iHani
Last active March 6, 2024 03:28
Show Gist options
  • Save iHani/a95b206b62672660ffd526eff958e397 to your computer and use it in GitHub Desktop.
Save iHani/a95b206b62672660ffd526eff958e397 to your computer and use it in GitHub Desktop.
Converts Arabic numbers chars to normal English numbers #JavaScript
/**
* Converts Arabic numeric chars to English.
* @param {Number} number - The Arabic number to be converted to English number.
* Thanks to whomever I stole this code from on the web a while ago.
* Michael Scott: It's whoever, not whomever.
* Ryan: It's whomever.
* Michael Scott: No, whomever is never acutally right.
* Jim Halpert: Nope, sometimes it's right.
* Creed: Michael is right. It's a made up word used to trick students-
*/
function englishinize(number) {
return number.replace(/[٠١٢٣٤٥٦٧٨٩]/g, (d) => parseInt((d.charCodeAt(0) - 1632)));
}
console.log(englishinize(٤٢٠));
// 420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment