Skip to content

Commit 564425a

Browse files
authored
Update isOdd.js
1 parent 18a28e5 commit 564425a

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

Maths/isOdd.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
// Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal.
2-
function isOdd (num) {
3-
if (num < 0) {
4-
num *= -1
5-
}
6-
7-
if (Math.floor(num) !== num) {
8-
console.error('Decimal Value')
9-
return null
10-
}
11-
12-
if (num % 2 === 1) {
13-
return true
14-
}
15-
16-
return false
1+
/*
2+
* function to check if number is odd
3+
* return true if number is odd
4+
* else false
5+
*/
6+
7+
const isOdd = (value) => {
8+
return !!((value & 1))
179
}
1810

11+
// testing
1912
console.log(isOdd(2))
2013
console.log(isOdd(3))

0 commit comments

Comments
 (0)