From 97ac1c3d248f52474d6957a8e3cdd7a93aff1961 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Feb 2019 15:00:42 -0600 Subject: [PATCH] fixed and added test cases --- Conversions/DecimalToHex.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Conversions/DecimalToHex.js b/Conversions/DecimalToHex.js index f95649b2a..ead26cceb 100644 --- a/Conversions/DecimalToHex.js +++ b/Conversions/DecimalToHex.js @@ -9,11 +9,16 @@ function intToHex(num){ } return num; } + function decimalToHex(num){ let hex_out = []; while(num > 15) { hex_out.push(intToHex(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");