DecimalToHex

- Add test file DecimalToHex.test.js
- Add export to DecimalToHex.js
- Remove console.log from DecimalToHex.js
This commit is contained in:
TrasherDK
2021-10-03 12:11:34 +02:00
parent c0fa45cc19
commit c35b20a4ce
2 changed files with 18 additions and 5 deletions

View File

@ -1,4 +1,4 @@
function intToHex (num) {
function intToHex(num) {
switch (num) {
case 10: return 'A'
case 11: return 'B'
@ -10,7 +10,7 @@ function intToHex (num) {
return num
}
function decimalToHex (num) {
function decimalToHex(num) {
const hexOut = []
while (num > 15) {
hexOut.unshift(intToHex(num % 16))
@ -19,6 +19,4 @@ function decimalToHex (num) {
return intToHex(num) + hexOut.join('')
}
// test cases
console.log(decimalToHex(999098) === 'F3EBA')
console.log(decimalToHex(123) === '7B')
export { decimalToHex }