mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
14 lines
357 B
TypeScript
14 lines
357 B
TypeScript
/**
|
|
* Determines if the number is a power of 2
|
|
* @param n The number to check.
|
|
*/
|
|
export function isPowerOfTwo(n: number) {
|
|
if (isNaN(n)) {
|
|
return false;
|
|
}
|
|
|
|
// Disabiling the bitwise rule because it's honestly the most effecient way to check for this.
|
|
// tslint:disable-next-line:no-bitwise
|
|
return n && (n & (n - 1)) === 0;
|
|
}
|