diff options
Diffstat (limited to 'util/array.ts')
-rw-r--r-- | util/array.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/util/array.ts b/util/array.ts index 76e2a9e..5b8c512 100644 --- a/util/array.ts +++ b/util/array.ts @@ -1,17 +1,23 @@ declare global { interface Array<T> { + /** @summary check if any of the elements of `arr2` are included in `this` */ anyOf(arr2: Array<T>): boolean; + /** @summary return last element of array without removing it */ peek(): T; + /** @summary create Set from this array */ + set(): Set<T>; } } -/** @summary check if any of the elements of `arr2` are included in `this` */ Array.prototype.anyOf = function(arr2) { return !!this.filter(e => arr2.includes(e)).length; }; -/** @summary return last element of array without removing it */ Array.prototype.peek = function() { return this[this.length - 1]; }; +Array.prototype.set = function() { + return new Set(this); +} + |