category | contributors | created | title | updated | |||
---|---|---|---|---|---|---|---|
Validator |
|
2020-05-06 |
Check if a number is odd |
2021-10-13 |
JavaScript version
const isOdd = (n) => n % 2 !== 0;
// Or
const isOdd = (n) => !!(n & 1);
// Or
const isOdd = (n) => !Number.isInteger(n / 2);
TypeScript version
const isOdd = (n: number): boolean => n % 2 !== 0;
// Or
const isOdd = (n: number): boolean => !!(n & 1);
// Or
const isOdd = (n: number): boolean => !Number.isInteger(n / 2);
Examples
isOdd(1); // true
isOdd(2); // false