Skip to content

Commit 97ac1c3

Browse files
committed
fixed and added test cases
1 parent 3e47ca6 commit 97ac1c3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Conversions/DecimalToHex.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ function intToHex(num){
99
}
1010
return num;
1111
}
12+
1213
function decimalToHex(num){
1314
let hex_out = [];
1415
while(num > 15) {
1516
hex_out.push(intToHex(num%16));
1617
num = Math.floor(num / 16);
1718
}
18-
return hex_out.join("");
19+
return intToHex(num) + return hex_out.join("");
1920
}
21+
22+
// test cases
23+
console.log(decimalToHex(999098) === "F3EBA");
24+
console.log(decimalToHex(123) === "7B");

0 commit comments

Comments
 (0)