Files
lowcode-frontend/src/utils/LRU.ts
2024-11-16 14:43:26 +08:00

16 lines
474 B
TypeScript

export function pushToStack(stack: string[], id: string): void {
if (stack.includes(id)) {
// 如果已经存在于栈中,先移除再插入到栈顶
stack.splice(stack.indexOf(id), 1);
}
stack.push(id);
}
export function popFromStack(stack: string[]): string | undefined {
return stack.pop();
}
export function topFromStack(stack: string[]): string | undefined {
return stack.at(-1); // 使用 .at() 方法访问最后一个元素
}