From 4971a298399bc13ab37ead6239a8b6491242bfc6 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 10 Oct 2020 13:37:40 -0700 Subject: [PATCH 1/8] Added isOdd function. --- Maths/isOdd.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Maths/isOdd.js diff --git a/Maths/isOdd.js b/Maths/isOdd.js new file mode 100644 index 000000000..22acc8deb --- /dev/null +++ b/Maths/isOdd.js @@ -0,0 +1,21 @@ +//Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal. +function isOdd (num) { + + if (num < 0) + { + num *= -1 + } + + if (Math.floor(num) !== num) + { + console.error('Decimal Value') + return null + } + + if (num % 2 === 1) + { + return true + } + + return false +} \ No newline at end of file From 008162228e59c731a1cbcd5d0bcaf33f34a0df74 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 10 Oct 2020 14:02:35 -0700 Subject: [PATCH 2/8] Add and fixed isOdd.js --- Maths/isOdd.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Maths/isOdd.js b/Maths/isOdd.js index 22acc8deb..7263ceafe 100644 --- a/Maths/isOdd.js +++ b/Maths/isOdd.js @@ -1,21 +1,17 @@ -//Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal. +// Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal. function isOdd (num) { - - if (num < 0) - { + if (num < 0) { num *= -1 } - if (Math.floor(num) !== num) - { + if (Math.floor(num) !== num) { console.error('Decimal Value') return null } - if (num % 2 === 1) - { + if (num % 2 === 1) { return true } - return false -} \ No newline at end of file + return false +} From 18a28e567ec660c19ca2d5cda54cd90654df7759 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 10 Oct 2020 14:07:16 -0700 Subject: [PATCH 3/8] Update isOdd.js --- Maths/isOdd.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Maths/isOdd.js b/Maths/isOdd.js index 7263ceafe..0641bf597 100644 --- a/Maths/isOdd.js +++ b/Maths/isOdd.js @@ -15,3 +15,6 @@ function isOdd (num) { return false } + +console.log(isOdd(2)) +console.log(isOdd(3)) From 564425ade760ed2fd34f8c759510128fe726a031 Mon Sep 17 00:00:00 2001 From: vinayak Date: Mon, 12 Oct 2020 13:15:57 +0530 Subject: [PATCH 4/8] Update isOdd.js --- Maths/isOdd.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Maths/isOdd.js b/Maths/isOdd.js index 0641bf597..fffe17930 100644 --- a/Maths/isOdd.js +++ b/Maths/isOdd.js @@ -1,20 +1,13 @@ -// Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal. -function isOdd (num) { - if (num < 0) { - num *= -1 - } +/* + * function to check if number is odd + * return true if number is odd + * else false + */ - if (Math.floor(num) !== num) { - console.error('Decimal Value') - return null - } - - if (num % 2 === 1) { - return true - } - - return false +const isOdd = (value) => { + return !!((value & 1)) } +// testing console.log(isOdd(2)) console.log(isOdd(3)) From b8b98a5972b72b9b986a953664385d39b003efe2 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 24 Oct 2020 01:37:27 -0700 Subject: [PATCH 5/8] Added decimalIsolate file. --- Maths/decimalIsolate.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Maths/decimalIsolate.js diff --git a/Maths/decimalIsolate.js b/Maths/decimalIsolate.js new file mode 100644 index 000000000..30b164089 --- /dev/null +++ b/Maths/decimalIsolate.js @@ -0,0 +1,15 @@ +/* + * function isolates the decimal part of a number. + * Take the number and subtract it from the floored number. + * Return the result. + */ + +const decimalIsolate = (number) => { + return number - Math.floor(number) + +} + +// testing +console.log(decimal_isolate(35.345)) +console.log(decimal_isolate(56.879)) +console.log(decimal_isolate(89.5643)) From 5f526eaef517e67913e1510fcbd598e2f6a6b04c Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 24 Oct 2020 01:39:52 -0700 Subject: [PATCH 6/8] Update decimalIsolate.js --- Maths/decimalIsolate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Maths/decimalIsolate.js b/Maths/decimalIsolate.js index 30b164089..ec23e9231 100644 --- a/Maths/decimalIsolate.js +++ b/Maths/decimalIsolate.js @@ -10,6 +10,6 @@ const decimalIsolate = (number) => { } // testing -console.log(decimal_isolate(35.345)) -console.log(decimal_isolate(56.879)) -console.log(decimal_isolate(89.5643)) +console.log(decimalIsolate(35.345)) +console.log(decimalIsolate(56.879)) +console.log(decimalIsolate(89.5643)) From ac4bd9f552e98dbfdfe27e74f4fa02546cfc61df Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 24 Oct 2020 01:45:59 -0700 Subject: [PATCH 7/8] Update decimalIsolate.js --- Maths/decimalIsolate.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Maths/decimalIsolate.js b/Maths/decimalIsolate.js index ec23e9231..026999cc6 100644 --- a/Maths/decimalIsolate.js +++ b/Maths/decimalIsolate.js @@ -5,8 +5,7 @@ */ const decimalIsolate = (number) => { - return number - Math.floor(number) - + return number - Math.floor(number) } // testing From ef78fce1e24434736b95a19984eac6c659d13e14 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Tue, 22 Dec 2020 11:08:56 +0530 Subject: [PATCH 8/8] Update decimalIsolate.js The previous code was not efficient enough to give the accurate output. --- Maths/decimalIsolate.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Maths/decimalIsolate.js b/Maths/decimalIsolate.js index 026999cc6..aae6e8ed7 100644 --- a/Maths/decimalIsolate.js +++ b/Maths/decimalIsolate.js @@ -5,10 +5,13 @@ */ const decimalIsolate = (number) => { - return number - Math.floor(number) + const ans = parseFloat((number + '').replace(/^[-\d]+./, '.')) + return isNaN(ans) === true ? 0 : ans } // testing console.log(decimalIsolate(35.345)) console.log(decimalIsolate(56.879)) console.log(decimalIsolate(89.5643)) +console.log(decimalIsolate(38.00)) +console.log(decimalIsolate(33))