Recently I added toBase() to YourJS. The purpose of this function is to make a straight-forward way to convert numbers to a base (from 2 to 36). Of course you can easily use native JavaScript by using Number.prototype.toString(), but the beauty of this function is that it also lets us define functions whose sole purpose is to convert numbers to a specific base. The following is an example of this, click Run to try it out:

If you ran the code above you will see that toBin, toOct, and toHex converted the numbers 1 to 100 to the corresponding bases. In addition, we see that we can call YourJS.toBase(numToConvert, base) (or JS.toBase(...) as used above due to the name specified in console.loadYourJS(...)).

Feel free to keep playing around with this function in the YourJS console above or you can open another console by clicking here. If you want to build your own YourJS navigate over to YourJS.com. As always, happy coding! šŸ˜Ž


Leave a Reply

Your email address will not be published. Required fields are marked *