Find out whether number is of Power of Two The task

is taken from leetcode


  Given an integer, write a function to determine if it is a power of
  two.
  
  Example 1:
  
  Input: 1
  
  Output: true 
  
  Explanation: 20 = 1
  
  Example 2:
  
  Input: 16
  
  Output: true
  
  Explanation: 24 = 16
  
  Example 3:
  
  Input: 218
  
  Output: false


My solution

/**
 * @param {number} n
 * @return {boolean}
 */
var isPowerOfTwo = function(n) {
  if (n &lt;= 0 ) { return false; }
  if (n &lt;= 2) { return true; }
  let num = n;
  do {
    const x = num / 2;
    if ((x | 0) !== x) { return false; }
    if (x === 2) { return true; }
    num = x;
  } while(num);
  return false;
};
I mean, I would use a library to do this. Namely, Math.log2



function isPowerOfTwo(n) {
  return Math.log2(n) % 1 === 0;
}

console.log(isPowerOfTwo(3)); //false
console.log(isPowerOfTwo(4)); //true
console.log(isPowerOfTwo(7)); //false
console.log(isPowerOfTwo(8)); //true
console.log(isPowerOfTwo(-1));//false