mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-26 06:34:20 +08:00
18 lines
438 B
TypeScript
18 lines
438 B
TypeScript
import { summary } from "./report.ts";
|
|
|
|
export class Inventory {
|
|
items: Map<string, number> = new Map();
|
|
add(name: string, qty: number): void {
|
|
this.items.set(name, (this.items.get(name) ?? 0) + qty);
|
|
}
|
|
count(): number {
|
|
let total = 0;
|
|
for (const qty of this.items.values()) total += qty;
|
|
return total;
|
|
}
|
|
}
|
|
|
|
export const stock = new Inventory();
|
|
stock.add("nut", 10);
|
|
console.log("inventory ready:", summary());
|