aboutsummaryrefslogtreecommitdiff
path: root/util/array.ts
blob: 5b8c512922939abee1d060c659330fa0c0e06f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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>;
	}
}

Array.prototype.anyOf = function(arr2) {
	return !!this.filter(e => arr2.includes(e)).length;
};

Array.prototype.peek = function() {
	return this[this.length - 1];
};

Array.prototype.set = function() {
	return new Set(this);
}