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",
|
"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"
|
||||||
|
@ -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",
|
||||||
|
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
|
* 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[]) {
|
||||||
|
items.forEach(el => {
|
||||||
const index = this.indexOf(el);
|
const index = this.indexOf(el);
|
||||||
if(index != -1) this.slice(index, 1);
|
if(index != -1) this.slice(index, 1);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user