63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
// ============================================================
|
|
// 第二阶段练习文件 — 迷宫导航
|
|
// ============================================================
|
|
//
|
|
// 练习 1:单词跳跃
|
|
// 用 w 从 "START" 跳到 "END",然后用 b 跳回来
|
|
// 例如:按 w w w w ... 按 b b b b ...
|
|
//
|
|
// 练习 2:使用 f 查找
|
|
// 用 fX 跳到标记 X 的位置,然后按 ; 到下一个 X
|
|
// 例如:fX → ; → ; → ; → ...
|
|
//
|
|
// 练习 3:用 / 搜索
|
|
// 用 /TODO 找到所有 TODO 标记,用 n 跳到下一个
|
|
//
|
|
// 练习 4:用 % 匹配括号
|
|
// 跳到任意 {}()[] 上按 %
|
|
//
|
|
// ============================================================
|
|
|
|
// START --X-- word1 word2 word3 --X-- word4 word5
|
|
// --X-- word6 word7 word8 --X-- word9 word10
|
|
|
|
function calc(a: number, b: number): number {
|
|
// TODO: implement complex calculation
|
|
if (a > b) {
|
|
return a + b; // --X-- destination
|
|
}
|
|
return b - a; // --X-- another point
|
|
}
|
|
|
|
interface Data {
|
|
id: number;
|
|
name: string;
|
|
tags: string[];
|
|
// TODO: add metadata field
|
|
}
|
|
|
|
const config = {
|
|
server: "localhost",
|
|
port: 3000,
|
|
debug: true,
|
|
// TODO: add production config
|
|
};
|
|
|
|
// --X-- mid1 --X-- mid2 --X-- mid3
|
|
|
|
class Something {
|
|
items: string[];
|
|
|
|
constructor(items: string[]) {
|
|
this.items = items;
|
|
}
|
|
|
|
// TODO: implement filter
|
|
filter(predicate: (item: string) => boolean): string[] {
|
|
return this.items.filter(predicate);
|
|
}
|
|
}
|
|
|
|
// --X-- near-end-1 --X-- near-end-2
|
|
// END
|