← Back to challenges

Power of Two

JavaScriptHardnumbersmathvalidation

Instructions

Write a function that returns true if an integer can be expressed as a power of base value 2 and false otherwise.

Examples

powerOfTwo(32) ➞ true

powerOfTwo(1) ➞ true

powerOfTwo(-7) ➞ false

powerOfTwo(18) ➞ false

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find the Bugs: Returning Valid Prices