-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.set.ts
More file actions
77 lines (69 loc) · 2.01 KB
/
index.set.ts
File metadata and controls
77 lines (69 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @author SNIPPIK
* @description Реализация функция из Array в Set
* @class SetArray
* @extends Set
* @public
*/
export class SetArray<T> extends Set<T> {
/**
* @description Выдаем коллекцию... Для дальнейшего использования
* @returns T[]
* @public
*/
public get array(): T[] {
return Array.from(this.values());
};
/**
* @description Добавление задачи в базу
* @param task - Задача
* @public
*/
public add(task: T) {
if (this.has(task)) this.delete(task);
super.add(task);
return this;
};
/**
* @description Удаляет элемент из массива
* @param item - объект задачи или item с next
* @returns true если элемент найден и удалён, иначе false
* @public
*/
public delete(item: T) {
if (!this.has(item)) {
this.delete(item);
return true;
}
super.delete(item);
return true;
};
/**
* @description Получаем объект из списка
* @param item - оригинальный объект
* @public
*/
public get(item: T) {
const array = this.array;
const index = array.indexOf(item);
return index > -1 ? array[index] : null;
};
/**
* @description Производим фильтрацию по функции
* @param predicate - Функция поиска
* @returns T[]
* @public
*/
public filter = (predicate: (item: T) => boolean): T[] => {
return this.array.filter(predicate);
};
/**
* @description Производим поиск объекта по функции
* @param predicate - Функция поиска
* @returns T[]
* @public
*/
public find = (predicate: (item: T) => boolean): T => {
return this.array.find(predicate);
};
}