Add or remove multiple elements from ASet at once
This commit is contained in:
parent
54a2880391
commit
3e8f5cc00b
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.1",
|
||||
"version": "0.17.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.1",
|
||||
"version": "0.17.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"var-persist": "^1.0.1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.1",
|
||||
"version": "0.17.2",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
16
src/aset.ts
16
src/aset.ts
@ -19,20 +19,22 @@ export class ASet<T> extends Array {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add single element to set if unique
|
||||
* @param {T} el Element to add
|
||||
* Add elements to set if unique
|
||||
* @param items
|
||||
*/
|
||||
add(el: T) {
|
||||
if(!this.has(el)) this.push(el);
|
||||
add(...items: T[]) {
|
||||
items.filter(el => !this.has(el)).forEach(el => this.push(el));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete element from set
|
||||
* @param {T} el Element that will be deleted
|
||||
* Delete elements from set
|
||||
* @param items Elements that will be deleted
|
||||
*/
|
||||
delete(el: T) {
|
||||
delete(...items: T[]) {
|
||||
items.forEach(el => {
|
||||
const index = this.indexOf(el);
|
||||
if(index != -1) this.slice(index, 1);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user