File tree Expand file tree Collapse file tree 1 file changed +16
-19
lines changed Expand file tree Collapse file tree 1 file changed +16
-19
lines changed Original file line number Diff line number Diff line change 1
- /*
2
- author: @dev-madhurendra
1
+ /**
2
+ * @author : dev-madhurendra
3
+ * Checks whether the given number is a power of four or not.
4
+ *
5
+ * A number is considered a power of four if and only if there is a single '1' bit in its binary representation,
6
+ * and that '1' bit is at the first position, followed by an even number of '0' bits.
7
+ *
8
+ * @param {number } n - The input number to check.
9
+ * @returns {boolean } True if the number is a power of four, false otherwise.
10
+ *
11
+ * @example
12
+ * const result = isPowerOfFour(16); // Returns true (16 is 4^2)
13
+ * const result2 = isPowerOfFour(5); // Returns false (5 is not a power of four)
14
+ */
15
+ const isPowerOfFour = ( n ) => ( ( n > 0 ) && ( ( n & n - 1 ) === 0 ) && ( n % 3 === 1 ) )
3
16
4
- This script will check whether the given
5
- number is a power of four or not.
6
-
7
- A number will be power of four if and only if there is a 1 in the binary
8
- of the digit and it will be at the first position and followed by even number of zeroes are there.
9
-
10
- n n-1%3==0 (n-1)'sbin (n)'sbin
11
- 1 0 0 1 - 4^0
12
- 4 3 011 100 - 4^1
13
- 16 15 01111 10000 - 4^2
14
- 64 63 011111 1000000 - 4^3
15
-
16
- */
17
-
18
- const IsPowerOfFour = ( n ) => ( ( n > 0 ) && ( ( n & n - 1 ) === 0 ) && ( n % 3 === 1 ) )
19
-
20
- export { IsPowerOfFour }
17
+ export { isPowerOfFour }
You can’t perform that action at this time.
0 commit comments