mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Add isPowerOfTwo function.
This commit is contained in:
7
src/algorithms/math/bits/isPowerOfTwo.js
Normal file
7
src/algorithms/math/bits/isPowerOfTwo.js
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @param {number} number
|
||||
* @return bool
|
||||
*/
|
||||
export default function isPowerOfTwo(number) {
|
||||
return (number & (number - 1)) === 0;
|
||||
}
|
||||
Reference in New Issue
Block a user