DeepSeek 编程助手

粘贴代码,排查报错,或请 DeepSeek 解释一段实现。免订阅,按实际用量付费,每次回复下方都能查看费用。

  • 新账号免费试用 DeepSeek Flash,额度 0.50 美元,无需绑卡
  • 邮箱验证码登录,不需要 Google 或 GitHub 账号
  • 微信支付、支付宝充值,¥25 起

中国大陆地区仅提供 DeepSeek 模型。

排查一个失败的 TypeScript 测试

真实运行DeepSeek Flash · 费用 $0.000222
测试任务
This TypeScript test expects "0 items", but receives "1 item":

function countLabel(count: number): string {
  return count <= 1 ? "1 item" : count + " items";
}

expect(countLabel(0)).toBe("0 items");

Explain the bug, make the smallest fix, and show tests for 0, 1, and 2 items.
DeepSeek Flash 的回答
## Bug

The condition groups `0` with `1`:

```ts
count <= 1 ? "1 item" : ...
```

So `0 <= 1` is true, and `countLabel(0)` returns `"1 item"` instead of `"0 items"`. Singular should apply only when the count is exactly `1`.

## Smallest fix

Change `<=` to `===`:

```ts
function countLabel(count: number): string {
  return count === 1 ? "1 item" : count + " items";
}
```

## Tests

```ts
describe("countLabel", () => {
  it("labels zero items", () => {
    expect(countLabel(0)).toBe("0 items");
  });

  it("labels one item", () => {
    expect(countLabel(1)).toBe("1 item");
  });

  it("labels two items", () => {
    expect(countLabel(2)).toBe("2 items");
  });
});
```

With the fix, these produce `"0 items"`, `"1 item"`, and `"2 items"` respectively.

真实运行记录 · 输入 149、输出 334 token,按 CodeMux 费率计费。