From 67dbb6421976254658c5e38045513129dd18187a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 28 Jun 2023 23:59:50 +0200 Subject: initial public commit --- util/set.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 util/set.ts (limited to 'util/set.ts') 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 { + anyOf(arr2: Array): boolean; + arr(): Array; + } +} + +/** @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; +}; + -- cgit v1.2.3