Add or remove multiple elements from ASet at once
All checks were successful
Build / Build NPM Project (push) Successful in 30s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 27s

This commit is contained in:
Zakary Timson 2024-10-06 19:14:36 -04:00
parent 54a2880391
commit 3e8f5cc00b
3 changed files with 14 additions and 12 deletions

4
package-lock.json generated
View File

@ -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"

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.17.1",
"version": "0.17.2",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -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) {
const index = this.indexOf(el);
if(index != -1) this.slice(index, 1);
delete(...items: T[]) {
items.forEach(el => {
const index = this.indexOf(el);
if(index != -1) this.slice(index, 1);
})
}
/**