Last active
October 30, 2019 20:38
-
-
Save xSAVIKx/3c309b88e5c3a132d198189beba958cd to your computer and use it in GitHub Desktop.
Converts numbers in string representation to their int representation using supplied radix.
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 glbl = global || globalThis || window; | |
const radixes = '0123456789абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; | |
const parseInt = (text, radix) => { | |
const actualRadix = radixes.indexOf(radix); | |
const result = glbl.parseInt(text, actualRadix); | |
return result; | |
}; | |
console.log(parseInt('210', 3)); // 21 | |
console.log(parseInt('210', 'а')); // 210 | |
console.log(parseInt('210', 'ё')); // 528 | |
console.log(parseInt('210', 'щ')); // 2628 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment