aboutsummaryrefslogtreecommitdiff
path: root/util/set.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-28 23:59:50 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-28 23:59:50 +0200
commit67dbb6421976254658c5e38045513129dd18187a (patch)
tree288b599d1097b26bdbcad3b6749b38e133017cf2 /util/set.ts
initial public commit
Diffstat (limited to 'util/set.ts')
-rw-r--r--util/set.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/util/set.ts b/util/set.ts
new file mode 100644
index 0000000..9790682
--- /dev/null
+++ b/util/set.ts
@@ -0,0 +1,17 @@
+declare global {
+ interface Set<T> {
+ anyOf(arr2: Array<T>): boolean;
+ arr(): Array<T>;
+ }
+}
+
+/** @summary return set items as array */
+Set.prototype.arr = function() {
+ return Array.from(this);
+}
+
+/** @summary check if any of the elements of `arr2` are included in `this` */
+Set.prototype.anyOf = function(arr2) {
+ return !!this.arr().filter(e => arr2.includes(e)).length;
+};
+