From 564425ade760ed2fd34f8c759510128fe726a031 Mon Sep 17 00:00:00 2001 From: vinayak Date: Mon, 12 Oct 2020 13:15:57 +0530 Subject: [PATCH] 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))