Rebuild training around a modular TS app

Replace the old exercise files (challenges, maze, sandbox, etc.)
with a runnable order/inventory TypeScript app under training/
that ships with unit tests, typecheck, lint, and format scripts.

Merge the full task checklist from TRAINING.md into README.md and
drop the obsolete docs and challenge files.

Add a root .gitignore for .zed, .reasonix, and build artifacts,
untrack the previously committed local configs, and fix the root
tsconfig to point at the new training sources.
This commit is contained in:
2026-09-09 23:34:48 +08:00
parent 1d19448cf2
commit 715ddb958a
60 changed files with 853 additions and 16811 deletions
+39
View File
@@ -0,0 +1,39 @@
// ════════════════════════════════════════════════════════════
// inventory —— 库存(被 orders 调用)
// 练习:/stock/ 搜索、]m [m 方法跳转、gA 查看引用
// ════════════════════════════════════════════════════════════
const stock = new Map<string, number>([
["apple", 40],
["banana", 60],
["milk", 20],
["bread", 15],
["egg", 120],
["cheese", 8],
]);
export class StockError extends Error {}
export function available(productId: string): number {
return stock.get(productId) ?? 0;
}
export function reserve(productId: string, quantity: number): void {
const left = available(productId);
if (quantity > left) {
throw new StockError(`Not enough stock for ${productId} (need ${quantity}, have ${left})`);
}
stock.set(productId, left - quantity);
}
export function release(productId: string, quantity: number): void {
stock.set(productId, available(productId) + quantity);
}
export function stockReport(): string[] {
const rows: string[] = [];
for (const [id, left] of stock) {
rows.push(`${id.padEnd(8)} ${String(left).padStart(3)} left`);
}
return rows;
}