Last active
March 6, 2024 03:28
-
-
Save iHani/a95b206b62672660ffd526eff958e397 to your computer and use it in GitHub Desktop.
Converts Arabic numbers chars to normal English numbers #JavaScript
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
/** | |
* 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