Skip to content

Instantly share code, notes, and snippets.

@utsukushiihime
Created December 12, 2020 06:42
Show Gist options
  • Save utsukushiihime/aace7597324d2d728f43932cdb20d918 to your computer and use it in GitHub Desktop.
Save utsukushiihime/aace7597324d2d728f43932cdb20d918 to your computer and use it in GitHub Desktop.
powerOfTwo JavaScript
const powerOfTwo = (num) => {
let pot = Math.pow(2, Math.ceil(Math.log2(num))) - num;
if (pot === 0) {
return "true";
} else {
return "false";
}
};
console.log(powerOfTwo(4));
console.log(powerOfTwo(124));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment