Skip to content

A list of odd ways for is-odd functions

License

Notifications You must be signed in to change notification settings

abiriadev/is-odd-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

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)

About

A list of odd ways for is-odd functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published