Last active
August 16, 2021 12:41
-
-
Save zkingboos/4fffbd779f94c1d90df7b7517c0c2b9b to your computer and use it in GitHub Desktop.
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
const value = prompt("Input required") | |
const base = prompt("Base required") | |
const adapters = { 16: { "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15 } } | |
const formula = value | |
.split("") | |
.reverse() | |
.map((item, index) => `${(adapters[base] || {})[item] || item} * ${base} ^ ${index}`) | |
.reverse() | |
.join(" + "); | |
alert(formula) |
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
Input required: FACA | |
Base required: 16 | |
Output: 15 * 16 ^ 3 + 10 * 16 ^ 2 + 12 * 16 ^ 1 + 10 * 16 ^ 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment