Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Number Base by vincent.tscherter
"use strict";
function numberRadix(str_number, radix){
var a = parseInt(str_number, radix), b = a.toString(radix);
return b==str_number.toLowerCase() ? a : -1
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(numberRadix("AF", 16), 175, "Hex");
assert.equal(numberRadix("101", 2), 5, "Bin");
assert.equal(numberRadix("101", 5), 26, "5 base");
assert.equal(numberRadix("Z", 36), 35, "Z base");
assert.equal(numberRadix("AB", 10), -1, "B > A > 10");
assert.equal(numberRadix("ASD",15), -1, "B > A > 10");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Sept. 1, 2018