[refactor] Moved 'compareArrays' to its own TS file

This commit is contained in:
Steven Evans 2018-07-05 16:50:51 -04:00
parent 1f7ed8f791
commit 6701503c78
4 changed files with 21 additions and 16 deletions

@ -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,

@ -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;
}