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", "name": "@ztimson/utils",
"version": "0.17.1", "version": "0.17.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.1", "version": "0.17.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"var-persist": "^1.0.1" "var-persist": "^1.0.1"

View File

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

View File

@ -19,20 +19,22 @@ export class ASet<T> extends Array {
} }
/** /**
* Add single element to set if unique * Add elements to set if unique
* @param {T} el Element to add * @param items
*/ */
add(el: T) { add(...items: T[]) {
if(!this.has(el)) this.push(el); items.filter(el => !this.has(el)).forEach(el => this.push(el));
} }
/** /**
* Delete element from set * Delete elements from set
* @param {T} el Element that will be deleted * @param items Elements that will be deleted
*/ */
delete(el: T) { delete(...items: T[]) {
const index = this.indexOf(el); items.forEach(el => {
if(index != -1) this.slice(index, 1); const index = this.indexOf(el);
if(index != -1) this.slice(index, 1);
})
} }
/** /**