For example, if the string passed to the function was "a" then the function would return "b". If the string was "2B" then it would return "2C". If the string was "d1k3" then the function would return "d1k4".
I think you get the idea. Also note that a upper case "A" would return an upper case "B" and a lower case "z" would go to the upper case letters; return "A". After "9" it's "a" etc.
I don't really have the idea on where I would start if I were to create such a function?
Thanks for reading guys.
EDIT: I've found out that parseInt() function accepts a radix which means I can use it to convert a string like "a" to an integer like "10". Which is great! In other words I can use parseInt() to convert a case-insensitive string of number and alphabet characters into an integer, then from there I simple add one to that integer. Now I need a way to transform that integer back into a base 36 string.
Latest toBase() Extension:
Code: Select all
var toBase = function (base,fromBase)
{
var symbolSheet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/".split("");
if (typeof fromBase != "undefined")
{
var decimal = 0;
for (var i=0; i < this.toString().length; i++)
{
decimal = decimal + (Math.pow(fromBase,i) * symbolSheet.toString().replace(',','','g').indexOf(this.toString().charAt(this.toString().length-(i+1))));
}
}
else
{
var decimal = this;
}
var conversion = "";
if (base > symbolSheet.length || base <= 1)
{
return false;
}
while (decimal >= 1)
{
conversion = symbolSheet[(decimal - (base*Math.floor(decimal / base)))] +conversion;
decimal = Math.floor(decimal / base);
}
return (base<11) ? parseInt(conversion): conversion;
}
String.prototype.toBase = toBase, Number.prototype.toBase = toBase;
delete toBase;