This file contains hidden or 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
/** | |
* Transform a number to any base based on a provided range. | |
* TODO: doesn't support floats. | |
* @param {number} baseTen A regular, primitive integer number | |
* @param {Array<string>} range And array of characters to represent the positional system. | |
* @returns {string} A representation of the provided number in the positional system provided. | |
*/ | |
const toBase = (baseTen, range = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')) => { | |
if (baseTen % 1 > 0) throw new TypeError('Only integers are supported') | |
if (baseTen === 0) return range[0] |