[refactor] Moved 'powerOfTwo' to 'isPowerOfTwo' TS file

This commit is contained in:
Steven Evans
2018-07-05 14:20:21 -04:00
parent 1a5208f78f
commit 015524f049
3 changed files with 15 additions and 9 deletions
+13
View File
@@ -0,0 +1,13 @@
/**
* 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;
}