From 446f88b189bdad556887d347501defe46abc89eb Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 1 Oct 2020 16:42:37 +0530 Subject: [PATCH 1/4] Added Oct to Decimal conversion --- Conversions/OctToDecimal.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Conversions/OctToDecimal.js diff --git a/Conversions/OctToDecimal.js b/Conversions/OctToDecimal.js new file mode 100644 index 0000000000..b2b3a4aa06 --- /dev/null +++ b/Conversions/OctToDecimal.js @@ -0,0 +1,15 @@ +function octalToDecimal (num) { + let dec = 0 + let base = 1 + while (num > 0) { + const r = num % 10 + num = Math.floor(num / 10) + dec = dec + (r * base) + base = base * 8 + } + return dec + } + +// test cases +console.log(octalToDecimal(56) === 46) +console.log(octalToDecimal(2365) === 1269) \ No newline at end of file From 6cd03db6e2be8056a746b51512230f7fc6c5ed9a Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 1 Oct 2020 16:52:37 +0530 Subject: [PATCH 2/4] Added the standard javascript style --- Conversions/OctToDecimal.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Conversions/OctToDecimal.js b/Conversions/OctToDecimal.js index b2b3a4aa06..3f9a092900 100644 --- a/Conversions/OctToDecimal.js +++ b/Conversions/OctToDecimal.js @@ -1,14 +1,14 @@ function octalToDecimal (num) { - let dec = 0 - let base = 1 - while (num > 0) { - const r = num % 10 - num = Math.floor(num / 10) - dec = dec + (r * base) - base = base * 8 - } - return dec + let dec = 0 + let base = 1 + while (num > 0) { + const r = num % 10 + num = Math.floor(num / 10) + dec = dec + (r * base) + base = base * 8 } + return dec +} // test cases console.log(octalToDecimal(56) === 46) From f00897a7b9c5bc9a55040d6d81e3fb3da3c8c44f Mon Sep 17 00:00:00 2001 From: vinayak Date: Thu, 1 Oct 2020 23:10:39 +0530 Subject: [PATCH 3/4] Update OctToDecimal.js --- Conversions/OctToDecimal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/OctToDecimal.js b/Conversions/OctToDecimal.js index 3f9a092900..fc6e8464dd 100644 --- a/Conversions/OctToDecimal.js +++ b/Conversions/OctToDecimal.js @@ -12,4 +12,4 @@ function octalToDecimal (num) { // test cases console.log(octalToDecimal(56) === 46) -console.log(octalToDecimal(2365) === 1269) \ No newline at end of file +console.log(octalToDecimal(2365) === 1269) From 8035c136b04e2f78492d81b341a5dcdf467d3bf2 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Fri, 2 Oct 2020 10:13:20 +0530 Subject: [PATCH 4/4] npx standard --fix filename is run successfully --- Conversions/OctToDecimal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/OctToDecimal.js b/Conversions/OctToDecimal.js index 3f9a092900..fc6e8464dd 100644 --- a/Conversions/OctToDecimal.js +++ b/Conversions/OctToDecimal.js @@ -12,4 +12,4 @@ function octalToDecimal (num) { // test cases console.log(octalToDecimal(56) === 46) -console.log(octalToDecimal(2365) === 1269) \ No newline at end of file +console.log(octalToDecimal(2365) === 1269)