Skip to content

Commit a791b32

Browse files
authored
Create 231-power-of-two.js
1 parent 8c968b9 commit a791b32

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

231-power-of-two.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} n
3+
* @return {boolean}
4+
*/
5+
const isPowerOfTwo = function(n) {
6+
let tmp = 0
7+
let idx = 0
8+
while(tmp <= n) {
9+
if((tmp = Math.pow(2, idx)) === n) {
10+
return true
11+
} else {
12+
idx += 1
13+
}
14+
}
15+
return false
16+
};

0 commit comments

Comments
 (0)