mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Update isOdd.js
This commit is contained in:
@ -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) {
|
* function to check if number is odd
|
||||||
if (num < 0) {
|
* return true if number is odd
|
||||||
num *= -1
|
* else false
|
||||||
}
|
*/
|
||||||
|
|
||||||
if (Math.floor(num) !== num) {
|
const isOdd = (value) => {
|
||||||
console.error('Decimal Value')
|
return !!((value & 1))
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num % 2 === 1) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// testing
|
||||||
console.log(isOdd(2))
|
console.log(isOdd(2))
|
||||||
console.log(isOdd(3))
|
console.log(isOdd(3))
|
||||||
|
Reference in New Issue
Block a user