Skip to content

Commit 8812f63

Browse files
committed
Small fixes + comply with JS standard styles.
1 parent 5a290c3 commit 8812f63

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Bit-Manipulation/IsPowerOfTwo.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
And we know that 1's complement is just opp. of that number.
1515
So, (n & (n-1)) will be 0.
1616
17-
For eg: (1000 & (1000-1))
17+
For eg: (1000 & (1000-1))
1818
1 0 0 0 // Original Number (8)
1919
0 1 1 1 // After Subtracting 1 (8-1 = 7)
2020
_______
@@ -23,6 +23,8 @@
2323
*/
2424

2525
export const IsPowerOfTwo = (n) => {
26-
if (n != 0 && (n & (n - 1)) == 0) return true
27-
else return false
26+
if (n > 0 && (n & (n - 1)) === 0) {
27+
return true
28+
}
29+
return false
2830
}

Bit-Manipulation/test/IsPowerOfTwo.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ test('Check if 0 is a power of 2 or not:', () => {
55
expect(res).toBe(false)
66
})
77

8-
test('Check if 0 is a power of 2 or not:', () => {
8+
test('Check if 1 is a power of 2 or not:', () => {
99
const res = IsPowerOfTwo(1)
10-
expect(res).toBe(false)
10+
expect(res).toBe(true)
1111
})
1212

1313
test('Check if 4 is a power of 2 or not:', () => {

0 commit comments

Comments
 (0)