Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 635 Bytes

check-if-a-number-is-odd.mdx

File metadata and controls

41 lines (31 loc) · 635 Bytes
category contributors created title updated
Validator
ietienam
Namysh
marcobiedermann
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