Last active
March 28, 2024 09:40
-
-
Save felladrin/7c7467b8228972985a466ef3a16d2b82 to your computer and use it in GitHub Desktop.
Knowing if a number is odd in JavaScript without using division.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isOdd } from "./isOdd.mjs"; | |
isOdd(7); // returns true | |
isOdd(8); // returns false | |
isOdd(9); // returns true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function isOdd(n) { | |
return Boolean(n & 1 == 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment