mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 21:53:50 +01:00
[refactor] Moved 'compareArrays' to its own TS file
This commit is contained in:
parent
1f7ed8f791
commit
6701503c78
@ -16,7 +16,7 @@ import {Settings} from "./Settings";
|
||||
|
||||
import {parse} from "../utils/acorn";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {compareArrays} from "../utils/HelperFunctions";
|
||||
import {compareArrays} from "../utils/helpers/compareArrays";
|
||||
import {arrayToString} from "../utils/helpers/arrayToString";
|
||||
import {roundToTwo} from "../utils/helpers/roundToTwo";
|
||||
import {isString} from "../utils/StringHelperFunctions";
|
||||
|
@ -36,7 +36,7 @@ import {parse, Node} from "../utils/acorn";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
import {compareArrays} from "../utils/HelperFunctions";
|
||||
import {compareArrays} from "../utils/helpers/compareArrays";
|
||||
import {createElement} from "../utils/uiHelpers/createElement";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions";
|
||||
import {roundToTwo} from "../utils/helpers/roundToTwo";
|
||||
|
@ -90,23 +90,9 @@ function clearSelector(selector) {
|
||||
}
|
||||
}
|
||||
|
||||
//Returns true if all elements are equal, and false otherwise
|
||||
//Assumes both arguments are arrays and that there are no nested arrays
|
||||
function compareArrays(a1, a2) {
|
||||
if (a1.length != a2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < a1.length; ++i) {
|
||||
if (a1[i] != a2[i]) {return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export {sizeOfObject,
|
||||
clearObject,
|
||||
clearEventListeners,
|
||||
compareArrays,
|
||||
clearEventListenersEl,
|
||||
removeElement,
|
||||
createAccordionElement,
|
||||
|
19
utils/helpers/compareArrays.ts
Normal file
19
utils/helpers/compareArrays.ts
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
/**
|
||||
* Does a shallow compare of two arrays to determine if they are equal.
|
||||
* @param a1 The first array
|
||||
* @param a2 The second array
|
||||
*/
|
||||
export function compareArrays<T>(a1: T[], a2: T[]) {
|
||||
if (a1.length !== a2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < a1.length; ++i) {
|
||||
if (a1[i] !== a2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue
Block a user