UNPKG

sussy-util

Version:
87 lines (86 loc) 3.1 kB
export default class Set<T> { private items; private checkFunction; constructor(...items: T[]); /** * If the item is not already in the array, add it * @param {T} item - T - The item to be pushed into the array. */ push(item: T): void; /** * finds and removes the item from the Set * @param {T} item - T - The item to delete */ delete(item: T): void; /** * @param {number} index - number - The index of the item to get * @returns The item at the index. */ get(index: number): T; /** * Returns true if the set is empty, false otherwise * @returns The return type is boolean. */ isEmpty(): boolean; /** * The length function returns the length of the items array * @returns The length of the items array. */ length(): number; /** * The clear() function clears the items in the Set */ clear(): void; /** * The clone function creates a new Set object and passes the items of the current Set object to * the new Set object * @returns A new Set object with the same items as the original Set object. */ clone(): Set<T>; /** * The remove function removes an item from the list at the specified index. * @param {number} index - number - The index of the item to remove. */ remove(index: number): void; /** * The spread operator (...) is used to convert the Set to an array * @returns An array of the items in the set. */ toArray(): T[]; /** * This function changes the check function to the one passed in as a parameter. * @param predicate - (a: T, b: T) => boolean */ changeCheckFunction(predicate: (a: T, b: T) => boolean): void; toString(): string; /** * It takes the items array and converts it to a JSON string. * @returns The JSON string representation of the items array. */ toJSONString(): string; /** * Returns true if the Set contains the specified item, false otherwise. * @param item - The item to search for in the Set. * @returns A boolean indicating whether the item exists in the Set. */ has(item: T): boolean; /** * Executes a provided callback function once for each item in the Set. * @param callback - A function to execute for each item in the Set. */ forEach(callback: (item: T) => void): void; each(callbackfn: (item: T) => void): void; /** * Returns a new Set that contains the items from both the current Set and another Set. * @param set - The Set to merge with the current Set. * @returns A new Set that contains items from both Sets. */ merge(set: Set<T>): Set<T>; /** * Returns a new Set that contains items from the current Set that are not present in another Set. * @param set - The Set to subtract from the current Set. * @returns A new Set that contains items from the current Set excluding those present in the other Set. */ subtract(set: Set<T>): Set<T>; [Symbol.iterator](): Iterator<T>; }