1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 02:44:45 +00:00

refactor(packages/stdlib): use toReversed method instead of reverese

This commit is contained in:
2024-04-18 10:26:16 +07:00
parent c90c17db93
commit 943e913e76

View File

@@ -110,7 +110,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
* @returns {T[]}
*/
public toArray(): T[] {
return this.stack.slice();
return this.stack.toReversed();
}
/**
@@ -119,7 +119,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
* @returns {string}
*/
public toString() {
return this.stack.reverse().toString();
return this.toArray().toString();
}
/**
@@ -128,7 +128,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
* @returns {IterableIterator<T>}
*/
public [Symbol.iterator]() {
return this.stack.reverse()[Symbol.iterator]();
return this.toArray()[Symbol.iterator]();
}
/**
@@ -137,7 +137,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
* @returns {AsyncIterableIterator<T>}
*/
public async *[Symbol.asyncIterator]() {
for (const element of this.stack.reverse()) {
for (const element of this.toArray()) {
yield element;
}
}