mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 21:53:50 +01:00
[refactor] Moved 'powerOfTwo' to 'isPowerOfTwo' TS file
This commit is contained in:
parent
1a5208f78f
commit
015524f049
@ -48,7 +48,7 @@ import {NetscriptPort} from "./NetscriptPort";
|
||||
|
||||
import Decimal from "decimal.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {powerOfTwo} from "../utils/HelperFunctions";
|
||||
import {isPowerOfTwo} from "../utils/helpers/isPowerOfTwo";
|
||||
import {arrayToString} from "../utils/helpers/arrayToString";
|
||||
import {createRandomIp} from "../utils/IPAddress";
|
||||
import {formatNumber, isHTML} from "../utils/StringHelperFunctions";
|
||||
@ -1548,7 +1548,7 @@ function NetscriptFunctions(workerScript) {
|
||||
}
|
||||
|
||||
ram = Math.round(ram);
|
||||
if (isNaN(ram) || !powerOfTwo(ram)) {
|
||||
if (isNaN(ram) || !isPowerOfTwo(ram)) {
|
||||
workerScript.scriptRef.log("ERROR: purchaseServer() failed due to invalid ram argument. Must be numeric and a power of 2");
|
||||
return "";
|
||||
}
|
||||
|
@ -110,17 +110,10 @@ function compareArrays(a1, a2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Returns bool indicating whether or not its a power of 2
|
||||
function powerOfTwo(n) {
|
||||
if (isNaN(n)) {return false;}
|
||||
return n && (n & (n-1)) === 0;
|
||||
}
|
||||
|
||||
export {sizeOfObject,
|
||||
clearObject,
|
||||
clearEventListeners,
|
||||
compareArrays,
|
||||
powerOfTwo,
|
||||
clearEventListenersEl,
|
||||
removeElement,
|
||||
createAccordionElement,
|
||||
|
13
utils/helpers/isPowerOfTwo.ts
Normal file
13
utils/helpers/isPowerOfTwo.ts
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user