UNPKG

mahler

Version:

A automated task composer and HTN based planner for building autonomous system agents

43 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnorderedArray = void 0; const deep_equal_1 = require("./deep-equal"); class UnorderedArrayImpl extends Array { static of(...items) { return new UnorderedArrayImpl(...items); } static from(items = []) { return new UnorderedArrayImpl(...Array.from(items)); } includes(value) { for (const elem of this) { if ((0, deep_equal_1.deepEqual)(value, elem)) { return true; } } return false; } difference(other) { const result = []; for (const elem of this) { if (!other.includes(elem)) { result.push(elem); } } return result; } equals(other) { // If the arrays have different length then return false // immediately if (other == null || this.length !== other.length) { return false; } // Otherwise the arrays are equal if A - B = B - A = 0 const otherArr = new UnorderedArrayImpl(...Array.from(other)); const diffA = this.difference(otherArr); const diffB = otherArr.difference(this); return diffA.length === 0 && diffB.length === 0; } } exports.UnorderedArray = UnorderedArrayImpl; //# sourceMappingURL=unordered-array.js.map