sussy-util
Version:
Util package made by me
61 lines (60 loc) • 2.01 kB
TypeScript
export default class Stack<T> {
private items;
constructor(initElm?: T[]);
/**
* The function takes a variable number of arguments of type T and pushes them into the items array
* @param {T[]} elm - T[]
*/
push(...elm: T[]): void;
/**
* If the stack is empty, throw an error, otherwise return the last item in the stack.
* @returns The last item in the array.
*/
peek(): T;
/**
* If the stack is empty, throw an error. Otherwise, remove the last item from the stack and return
* it.
* @returns The last item in the array.
*/
pop(): T;
/**
* The function returns true if the stack is empty, false otherwise
* @returns The method returns a boolean value.
*/
empty(): boolean;
toString(): string;
toArray(): T[];
/**
* It takes the items array and converts it to a JSON string.
* @returns The JSON string representation of the items array.
*/
toJSONString(): string;
/**
* Returns the number of elements in the stack.
* @returns The number of elements in the stack.
*/
size(): number;
/**
* Returns a new stack that is a copy of the current stack.
* @returns A new stack with the same elements as the current stack.
*/
clone(): Stack<T>;
clear(): void;
/**
* Returns a new stack that contains the reversed order of the elements in the current stack.
* @returns {Stack<T>} A new stack with reversed elements.
*/
reverse(): Stack<T>;
/**
* Removes all occurrences of a specific element from the stack.
* @param {T} element - The element to be removed.
* @returns {number} The number of elements removed from the stack.
*/
removeAll(element: T): number;
/**
* Returns a new stack that contains the unique elements from the current stack.
* @returns {Stack<T>} A new stack with unique elements.
*/
distinct(): Stack<T>;
[Symbol.iterator](): Iterator<T>;
}