Day 5 - Final Review
Day 5 - 期末复习
🎯 Exam Problem-Solving Strategies
🎯 考试解题策略
Master the 5-Step Method, Question Types & HTTP Status Codes
掌握5步解题法、题型分类与HTTP状态码
📊 Question Type Classification Matrix
📊 题型分类矩阵
Understanding question types is the first step to exam success. Each type has distinct characteristics and focus areas.
理解题型是考试成功的第一步。每种类型都有独特的特征和考点。
| Type类型 |
Characteristics特征 |
Key Focus Areas考点 |
Example题号示例 |
| Pure Function纯函数 |
No HTTP, no server, only input/output无HTTP、无server、只有输入输出 |
Array ops, string handling, file I/O, logic数组操作、字符串处理、文件I/O、逻辑判断 |
Q23 |
| REST APIREST API |
Express routes, swagger.yamlExpress routes、swagger.yaml |
HTTP status codes, routing, req/res handlingHTTP状态码、路由处理、请求响应 |
Q24 |
| Business Logic业务逻辑 |
Complex conditions, notification systems复杂条件判断、notification系统 |
State machines, array search, string matching状态机、数组查找、字符串匹配 |
Q25 |
| Testing测试 |
.test.ts files.test.ts文件 |
Jest, expect assertions, edge casesJest、expect、edge case |
All questions各题都有 |
🔧 Q23 Type - Pure Function (e.g., Cockroaches)
🔧 Q23类型 - 纯函数 (如 Cockroaches)
Characteristics:特征:
Only function signature + interface, no Express/server, pure input→process→output
只有函数签名 + interface,没有Express/server,纯输入→处理→输出
Step 1: Read Interface
Step 1: 看interface
- Input type?
string[] (file paths)输入是什么?string[] (文件路径数组)
- Output type?
DecontaminateResult输出是什么?DecontaminateResult
- Intermediate data? locations array需要什么中间数据?locations数组
Code Template代码模板
async function decontaminate(files: string[]): Promise<DecontaminateResult> {
const result = { attic: 0, bathroom: 0, bedroom: 0, kitchen: 0 };
for (const file of files) {
const content = await fs.promises.readFile(file, 'utf-8');
const locations = content.split('\n').filter(Boolean);
for (const loc of locations) {
if (loc in result) {
result[loc as keyof typeof result]++;
}
}
}
return result;
}
Key Points:考点:
fs.readFileSync vs fs.promises.readFile
- async/await
- Array operations: split, filter, map数组操作: split, filter, map
- TypeScript type definitionsTypeScript类型定义
🌐 Q24 Type - REST API (e.g., Brooms)
🌐 Q24类型 - REST API (如 Brooms)
Characteristics:特征:
swagger.yaml defines API, Express server framework, multiple endpoints + error handling
swagger.yaml定义API,Express server框架,多个endpoint + 错误处理
Step 1: Read swagger.yaml (MOST IMPORTANT!)Step 1: 读swagger.yaml (最重要!)
| Endpoint |
Method |
Parameters参数 |
Returns返回 |
| /clear |
DELETE |
none无 |
{} |
| /user |
POST |
header + body |
{userId} |
| /message |
POST |
body |
{msgId} |
| /message/{from}/{to} |
GET |
path + query |
{msgs} |
| /message/{id} |
PUT |
path + body |
{msg} |
Step 2: Design Data StorageStep 2: 设计数据存储
interface DataStore {
users: User[]; // {userId, username}
messages: Message[]; // {messageId, from, to, message}
}
let dataStore: DataStore = { users: [], messages: [] };
let nextUserId = 1;
let nextMessageId = 1;
Step 3: Write HTTP LayerStep 3: 写HTTP层
// server.ts - HTTP wrapper
import { addUser } from './brooms';
app.post('/user', (req, res) => {
const { username } = req.body;
const role = req.header('role');
const result = addUser(username, role || '');
if ('error' in result) {
const statusCode = getStatusCode(result.error);
return res.status(statusCode).json(result);
}
res.json(result);
});
⚙️ Q25 Type - Business Logic (e.g., Thiscord)
⚙️ Q25类型 - 业务逻辑 (如 Thiscord)
Key Strategy:关键策略:
Reverse-engineer rules from test cases! Tests tell you EXACTLY what's expected.
从测试用例反向推导规则!测试告诉你精确的期望结果。
Step 1: Extract Rules from TestsStep 1: 从test反向推导规则
✗ Test 1: status='do not disturb' → false
✗ Test 2: channel in silenced → false
✓ Test 3: message contains @username → true
✓ Test 4: dm=true → true
✓ Test 5: channel in subscribed → true✗ Test 1: status='do not disturb' → false
✗ Test 2: channel在silenced里 → false
✓ Test 3: message包含@username → true
✓ Test 4: dm=true → true
✓ Test 5: channel在subscribed里 → true
Step 2: Draw Decision TreeStep 2: 画决策树
notificationService(user, message):
│
├─ 1. dm === true → return true
│
├─ 2. content contains @{username} → return true
│
├─ 3. status === 'do not disturb' → return false
│
├─ 4. channel in silenced → return false
│
├─ 5. channel in subscribed → return true
│
└─ 6. otherwise → return falsenotificationService(user, message):
│
├─ 1. dm === true → return true
│
├─ 2. content包含@{username} → return true
│
├─ 3. status === 'do not disturb' → return false
│
├─ 4. channel在silenced里 → return false
│
├─ 5. channel在subscribed里 → return true
│
└─ 6. 其他 → return false
Step 3: Write Code (Follow Decision Tree Order!)Step 3: 写代码 (按决策树顺序!)
function notificationService(user: User, message: Message): boolean {
// Rule 1: DM always notify
if (message.dm) return true;
// Rule 2: @mention always notify
if (message.content.includes(`@${user.username}`)) return true;
// Rule 3: Do not disturb blocks everything else
if (user.status === 'do not disturb') return false;
// Rule 4: Silenced channel
if (user.silenced.includes(message.channel)) return false;
// Rule 5: Subscribed channel
if (user.subscribed.includes(message.channel)) return true;
// Default: no notification
return false;
}
Key Points:考点:
- Complex condition logic复杂条件判断
- Short-circuit logic (priority matters!)短路逻辑 (优先级!)
- String operations: includes, indexOf字符串操作: includes, indexOf
- Array operations: includes数组操作: includes