mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
fixed and added test cases
This commit is contained in:
@ -9,11 +9,16 @@ function intToHex(num){
|
|||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decimalToHex(num){
|
function decimalToHex(num){
|
||||||
let hex_out = [];
|
let hex_out = [];
|
||||||
while(num > 15) {
|
while(num > 15) {
|
||||||
hex_out.push(intToHex(num%16));
|
hex_out.push(intToHex(num%16));
|
||||||
num = Math.floor(num / 16);
|
num = Math.floor(num / 16);
|
||||||
}
|
}
|
||||||
return hex_out.join("");
|
return intToHex(num) + return hex_out.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test cases
|
||||||
|
console.log(decimalToHex(999098) === "F3EBA");
|
||||||
|
console.log(decimalToHex(123) === "7B");
|
||||||
|
Reference in New Issue
Block a user