Files
vimx/challenges/code-golf.md
T

160 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🏌️ Code Golf — 代码高尔夫
> 用最少的按键完成编辑任务。记录你的按键数,挑战用更少的按键完成!
## 规则
- 只能用 Vim 快捷键,不能使用鼠标
- 记录按键数(不包括撤销的 `u`)
- 每次完成后在表格填入你的最佳成绩
---
## 场景 1:函数签名修改
**起始代码**:
```typescript
function greet(name: string): string {
return "Hello, " + name;
}
```
**目标代码**:
```typescript
function sayHelloTo(firstName: string, lastName: string): string {
return `Hello, ${firstName} ${lastName}!`;
}
```
| 日期 | 按键数 | 操作日志 |
|------|--------|----------|
| | | |
---
## 场景 2:对象属性重排
**起始代码**:
```typescript
const user = {
id: 1,
name: "Alice",
email: "alice@example.com",
age: 30,
};
```
**目标代码**:
```typescript
const user = {
name: "Alice",
email: "alice@example.com",
age: 30,
id: 1,
};
```
| 日期 | 按键数 | 操作日志 |
|------|--------|----------|
| | | |
---
## 场景 3:批量加注释
**起始代码**:
```typescript
function add(a: number, b: number): number {
return a + b;
}
function subtract(a: number, b: number): number {
return a - b;
}
function multiply(a: number, b: number): number {
return a * b;
}
```
**目标代码**:
```typescript
// Arithmetic operation: add
function add(a: number, b: number): number {
return a + b;
}
// Arithmetic operation: subtract
function subtract(a: number, b: number): number {
return a - b;
}
// Arithmetic operation: multiply
function multiply(a: number, b: number): number {
return a * b;
}
```
💡 提示:用宏!`qa` → 在第一行编辑 → `j` → `q` → `@a`
| 日期 | 按键数 | 操作日志 |
|------|--------|----------|
| | | |
---
## 场景 4:数组转对象
**起始代码**:
```typescript
const keys = ["name", "age", "email"];
const values = ["Alice", 30, "alice@example.com"];
```
**目标代码**:
```typescript
const person = {
name: "Alice",
age: 30,
email: "alice@example.com",
};
const keys = ["name", "age", "email"];
const values = ["Alice", 30, "alice@example.com"];
```
| 日期 | 按键数 | 操作日志 |
|------|--------|----------|
| | | |
---
## 场景 5:删除所有 console.log
**起始代码**:
```typescript
function process(): void {
console.log("Starting...");
const a = doThing();
console.log("After thing:", a);
const b = doOtherThing();
console.log("After other:", b);
console.log("Done!");
return b;
}
```
**目标代码**:
```typescript
function process(): void {
const a = doThing();
const b = doOtherThing();
return b;
}
```
💡 提示:用 `g l` 选中所有 `console.log` 行!
| 日期 | 按键数 | 操作日志 |
|------|--------|----------|
| | | |