Skip to content

Latest commit

 

History

History
37 lines (32 loc) · 575 Bytes

README.md

File metadata and controls

37 lines (32 loc) · 575 Bytes

awesome-is-odd

A list of odd ways for is-odd functions with Javascript.

The most common way

function isOdd(n) {
  return n % 2 === 1;
}

a bit weird way:

function isOdd(n) {
  return n & 1
}

Odd ways

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:

const isOdd = n => !n ? false : n < 0 ? true : isOdd(n - 2)