import "./set.ts"; declare global { interface Array { /** @summary check if any of the elements of `arr2` are included in `this` */ anyOf(arr2: Array): boolean; /** @summary return last element of array without removing it */ peek(): T; /** @summary create Set from this array */ set(): Set; /** @summary clear array */ clear(): void; /** @summary filter duplicates from array */ filterDuplicates(): Array; /** @summary `true` if the array doesn't contain duplicate items */ isUniq(): boolean; } } Array.prototype.anyOf = function(arr2) { return !!this.filter(e => arr2.includes(e)).length; }; Array.prototype.peek = function() { return this[this.length - 1]; }; Array.prototype.set = function() { return new Set(this); } Array.prototype.clear = function() { while (this.length > 0) this.pop(); } Array.prototype.filterDuplicates = function() { return this.set().arr(); // TODO: optimize this } Array.prototype.isUniq = function() { return this.length == this.filterDuplicates().length; }