From 4971a298399bc13ab37ead6239a8b6491242bfc6 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 10 Oct 2020 13:37:40 -0700 Subject: [PATCH 1/4] 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 0000000000..22acc8deb6 --- /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/4] 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 22acc8deb6..7263ceafe6 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/4] Update isOdd.js --- Maths/isOdd.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Maths/isOdd.js b/Maths/isOdd.js index 7263ceafe6..0641bf597e 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/4] Update isOdd.js --- Maths/isOdd.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Maths/isOdd.js b/Maths/isOdd.js index 0641bf597e..fffe17930c 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 - } - - if (Math.floor(num) !== num) { - console.error('Decimal Value') - return null - } - - if (num % 2 === 1) { - return true - } - - return false +/* + * function to check if number is odd + * return true if number is odd + * else false + */ + +const isOdd = (value) => { + return !!((value & 1)) } +// testing console.log(isOdd(2)) console.log(isOdd(3))