Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if a number is odious
function isOdious(x) {
if (x < 0) throw new Error('Value must be positive!')
const binaryExpansion = x.toString(2)
const count = Array.from(binaryExpansion).reduce((acc, val) => (val == 1 ? acc + 1 : acc), 0)
return count % 2 === 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment