Skip to content

Commit 82b11c7

Browse files
author
madhuredra
committed
used proper JSDoc comment and fixed test issues
1 parent e1fb577 commit 82b11c7

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

Bit-Manipulation/IsPowerofFour.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
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))
316

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 }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy