diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-28 23:59:50 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-28 23:59:50 +0200 |
commit | 67dbb6421976254658c5e38045513129dd18187a (patch) | |
tree | 288b599d1097b26bdbcad3b6749b38e133017cf2 /util/array.ts |
initial public commit
Diffstat (limited to 'util/array.ts')
-rw-r--r-- | util/array.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/util/array.ts b/util/array.ts new file mode 100644 index 0000000..76e2a9e --- /dev/null +++ b/util/array.ts @@ -0,0 +1,17 @@ +declare global { + interface Array<T> { + anyOf(arr2: Array<T>): boolean; + peek(): 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]; +}; + |