mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-11 07:06:13 +08:00
Add and fixed isOdd.js
This commit is contained in:
@ -1,19 +1,15 @@
|
|||||||
//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) {
|
function isOdd (num) {
|
||||||
|
if (num < 0) {
|
||||||
if (num < 0)
|
|
||||||
{
|
|
||||||
num *= -1
|
num *= -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.floor(num) !== num)
|
if (Math.floor(num) !== num) {
|
||||||
{
|
|
||||||
console.error('Decimal Value')
|
console.error('Decimal Value')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num % 2 === 1)
|
if (num % 2 === 1) {
|
||||||
{
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user