A list of odd ways for is-odd functions with Javascript.
function isOdd(n) {
return n % 2 === 1;
}
a bit weird way:
function isOdd(n) {
return n & 1
}
like above, but via string.
const isOdd = _ => /1$/.test(_.toString(2))
dumb for express
function isOdd(n) {
if (n < 0) n = Math.abs(n);
let result = false;
for (let i = 0; i < n; i++) result = !result;
return result;
}
recursive check:
function isOdd(n) {
return !n ? false : n < 0 ? true : isOdd(n - 2)
}