-
-
Save lwebber/7401d525a178934710321efcf08386a0 to your computer and use it in GitHub Desktop.
is Power of Two created by wwebby1 - https://repl.it/E87A/2
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
// # Write a method that takes in a number and returns true if it is a | |
// # power of 2. Otherwise, return false. | |
// # | |
// # You may want to use the `%` modulo operation. `5 % 2` returns the | |
// # remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case | |
// # of `6 % 2`, since 2 evenly divides 6 with no remainder, `6 % 2 == 0`. | |
// # | |
function isPowerOf2(num){ | |
var base = Math.log2(num); | |
if(Number.isInteger(base)) | |
return true; | |
else | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment