diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-02 19:21:39 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-02 19:21:39 +0200 |
commit | f4963b89ee542592e9ae95ca29d74ddc57841c3f (patch) | |
tree | f9ae82ae9549330d12a30ffee8960f2577fff9aa /util/array.ts | |
parent | ce9e0788317b25e5d297ed38d9fed0754a341288 (diff) |
implement Japanese class
Diffstat (limited to 'util/array.ts')
-rw-r--r-- | util/array.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util/array.ts b/util/array.ts index f032935..c5a26c6 100644 --- a/util/array.ts +++ b/util/array.ts @@ -1,3 +1,5 @@ +import "./set.ts"; + declare global { interface Array<T> { /** @summary check if any of the elements of `arr2` are included in `this` */ @@ -8,6 +10,10 @@ declare global { set(): Set<T>; /** @summary clear array */ clear(): void; + /** @summary filter duplicates from array */ + filterDuplicates(): Array<T>; + /** @summary `true` if the array doesn't contain duplicate items */ + isUniq(): boolean; } } @@ -27,3 +33,11 @@ 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; +} + |