Created
June 7, 2020 19:30
-
-
Save spencerbyw/b20239c2499c4bd0b89f671bd2c3c493 to your computer and use it in GitHub Desktop.
Weekly interview question from https://buttondown.email/cassidoo/archive/3fe14767-45d4-4796-807f-fadc95afb685
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
function nIsAPowerOfTwo(num) { | |
return (Math.log2(num) % 1) === 0; | |
} | |
// > nIsAPowerOfTwo(0); | |
// false | |
// > nIsAPowerOfTwo(1); | |
// true | |
// > nIsAPowerOfTwo(2); | |
// true | |
// > nIsAPowerOfTwo(3); | |
// false | |
// > nIsAPowerOfTwo(1024); | |
// true | |
// > nIsAPowerOfTwo(3.1415926535); | |
// false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment