DrillLab
Coding 题Coding problems

一道一道写One problem at a time

全站 25 道成型的 coding 题都在这儿。题面、需求、参考答案全部引用原来那一节,不是另抄一份。其中 21 道能直接在浏览器里写完并跑测试。All 25 coding problems, pulled from the lessons rather than copied. 21 of them run in the browser.

0 / 25道打过勾ticked done
只有你自己打勾才会加。不做自动判定 —— 测试绿了不等于你不看答案也能写出来。Only your own tick counts. Green tests do not prove you could write it again from scratch.
先读题,别先看答案Read the problem before the answer

每道题的页面默认只有题面 —— 工作区要点一下才开,讲解和答案在门后面。这个顺序是故意的:先自己卡住一会儿,后面看讲解才有用。Each page shows only the problem by default — the workspace opens on a click, and the walkthrough and answer sit behind gates. That order is deliberate: getting stuck for a while first is what makes the walkthrough worth reading.

沙箱有两档。第一遍用带脚手架学会;第二遍点空白重来,实现文件全清空,只留测试 —— 那一遍才算验收。The sandbox has two modes. Learn it the first time with the scaffold; the second time hit Blank slate — every implementation file is emptied and only the tests remain. That pass is the one that counts.

题目Problems

筛出 25 道。25 of 25 problems.
  1. Todo ListReact简单Easy约 25 分钟~25 min浏览器里能跑Runs in the browser8 条验收标准8 acceptance criteria
  2. 计时器(useEffect 清理函数)Timer (useEffect cleanup)React中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser6 条验收标准6 acceptance criteria
  3. fetch 取数:loading、error 与竞态Fetching data: loading, error and race conditionsReact困难Hard约 35 分钟~35 min本机跑Run it locally5 条验收标准5 acceptance criteria
  4. 递归评论树 + 树形不可变更新Recursive comment tree, updated without changing the originalReact困难Hard约 35 分钟~35 min浏览器里能跑Runs in the browser8 条验收标准8 acceptance criteria
  5. 主题切换(Context + value 记忆化)Theme switch (Context plus a memoised value)React中等Medium约 30 分钟~30 min浏览器里能跑Runs in the browser7 条验收标准7 acceptance criteria
  6. 星级评分(hover 预览 + 受控双模式)Star rating (hover preview, controlled and uncontrolled)React中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser7 条验收标准7 acceptance criteria
  7. 写一个自定义 hook:useLocalStorageWrite a custom hook: useLocalStorageReact中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser7 条验收标准7 acceptance criteria
  8. Kanban 看板:一次改两个数组Kanban board: changing two arrays at onceReact困难Hard约 40 分钟~40 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  9. Tabs 组件(只用一个 state)Tabs component (one piece of state only)React简单Easy约 20 分钟~20 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  10. 播放器(useRef 操作 DOM)Media player (touching the DOM with useRef)React中等Medium约 25 分钟~25 min本机跑Run it locally6 条验收标准6 acceptance criteria
  11. Dropdown:点外面要关掉Dropdown: close it on an outside clickReact中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  12. Redux Toolkit 版 TodoTodo with Redux ToolkitReact困难Hard约 40 分钟~40 min浏览器里能跑Runs in the browser6 条验收标准6 acceptance criteria
  13. Cab Booking(Context 版)Cab Booking (Context version)React困难Hard约 45 分钟~45 min浏览器里能跑Runs in the browser12 条验收标准12 acceptance criteria
  14. Notes Manager 增删改(React 考试 Q1)Notes Manager: add, edit and delete (React exam Q1)React困难Hard约 60 分钟~60 min浏览器里能跑Runs in the browser8 条验收标准8 acceptance criteria
  15. 带并发上限的异步任务调度器(Q2)Async task scheduler with a concurrency limit (Q2)JavaScript困难Hard约 45 分钟~45 min浏览器里能跑Runs in the browser6 条验收标准6 acceptance criteria
  16. 手写 debounce(带 cancel)Write debounce yourself (with cancel)JavaScript简单Easy约 15 分钟~15 min浏览器里能跑Runs in the browser4 条验收标准4 acceptance criteria
  17. 手写 throttle(leading + trailing)Write throttle yourself (leading and trailing)JavaScript中等Medium约 20 分钟~20 min浏览器里能跑Runs in the browser4 条验收标准4 acceptance criteria
  18. 手写 deepClone(防循环)Write deepClone yourself (handling cycles)JavaScript中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  19. 手写 flatten(depth 语义对齐原生)Write flatten yourself (depth behaves like the built-in)JavaScript简单Easy约 15 分钟~15 min浏览器里能跑Runs in the browser4 条验收标准4 acceptance criteria
  20. 手写 curry(部分应用可复用)Write curry yourself (reusable partial application)JavaScript简单Easy约 15 分钟~15 min浏览器里能跑Runs in the browser3 条验收标准3 acceptance criteria
  21. 手写 Promise.all + allSettledWrite Promise.all and allSettled yourselfJavaScript中等Medium约 25 分钟~25 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  22. 手写 EventEmitter(on/off/once/emit)Write EventEmitter yourself (on / off / once / emit)JavaScript中等Medium约 20 分钟~20 min浏览器里能跑Runs in the browser4 条验收标准4 acceptance criteria
  23. 手写 LRUCache(用 Map 的插入序)Write LRUCache yourself (using Map insertion order)JavaScript中等Medium约 20 分钟~20 min浏览器里能跑Runs in the browser5 条验收标准5 acceptance criteria
  24. Orders subgraph:四个 resolver + DataLoaderOrders subgraph: four resolvers and DataLoaderGraphQL困难Hard约 90 分钟~90 min本机跑Run it locally13 条验收标准13 acceptance criteria
  25. 六个 Spring Boot REST 端点Six Spring Boot REST endpointsJava / Spring困难Hard约 75 分钟~75 min本机跑Run it locally11 条验收标准11 acceptance criteria

为什么有的跑不了Why some can't run here

GraphQL subgraph 要真起一个服务,Spring 那道要 JVM 和 Maven —— 浏览器里都办不到。这两道给的是本机命令和期望输出,不给假编辑器。The GraphQL subgraph needs a real server process, and the Spring one needs a JVM and Maven — neither can happen in a browser. Those two hand you local commands and the expected output, not a fake editor.