Skip to content

Instantly share code, notes, and snippets.

@xSAVIKx
Last active October 30, 2019 20:38
Show Gist options
  • Save xSAVIKx/3c309b88e5c3a132d198189beba958cd to your computer and use it in GitHub Desktop.
Save xSAVIKx/3c309b88e5c3a132d198189beba958cd to your computer and use it in GitHub Desktop.
Converts numbers in string representation to their int representation using supplied radix.
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