mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00

* chore: Switch to Node 20 + Vitest * chore: migrate to vitest mock functions * chore: code style (switch to prettier) * test: re-enable long-running test Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime! see #1193 * chore: code style * chore: fix failing tests * Updated Documentation in README.md * Update contribution guidelines to state usage of Prettier * fix: set prettier printWidth back to 80 * chore: apply updated code style automatically * fix: set prettier line endings to lf again * chore: apply updated code style automatically --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
18 lines
693 B
JavaScript
18 lines
693 B
JavaScript
/**
|
|
* @author : dev-madhurendra
|
|
* Checks whether the given number is a power of four or not.
|
|
*
|
|
* A number is considered a power of four if and only if there is a single '1' bit in its binary representation,
|
|
* and that '1' bit is at the first position, followed by an even number of '0' bits.
|
|
*
|
|
* @param {number} n - The input number to check.
|
|
* @returns {boolean} True if the number is a power of four, false otherwise.
|
|
*
|
|
* @example
|
|
* const result = isPowerOfFour(16); // Returns true (16 is 4^2)
|
|
* const result2 = isPowerOfFour(5); // Returns false (5 is not a power of four)
|
|
*/
|
|
const isPowerOfFour = (n) => n > 0 && (n & (n - 1)) === 0 && n % 3 === 1
|
|
|
|
export { isPowerOfFour }
|