AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {number} n
* @return {boolean}
*/
let isPowerOfTwo = function(n) {
if (n < 1) {
return false;
}
let powerOfTwo = 1;
while (powerOfTwo < n) {
powerOfTwo *= 2;
}
return powerOfTwo === n;
};