AI Native 分级编程挑战

第2级 · 实战 · 状态与工作流程

重建任务状态

根据操作日志重建待办列表的最终状态。

题目说明

编写 function solution(actions)。输入输出均为 JSON 值,不要修改输入数组或对象。不支持外部库、网络访问及异步函数。 actions 是 {type:string,id:string,title?:string} 数组,从空列表开始。add 仅在 id 非空字符串、trim 后 title 非空且 ID 不存在时添加 {id,title:修剪后值,completed:false};忽略重复 add。update 修改已有项的 title 并 trim,忽略空 title。toggle 反转已有项的 completed,remove 删除。忽略不存在的 ID 和未知 type。按插入顺序返回当前项;删除后重新添加的 ID 排在末尾。 输入范围:每个输入数组最多50,000项,每个字符串最多1,000个字符。数字必须有限,整数及整数累计结果在JavaScript安全整数范围内。其他类型和有效性遵循上述规则。

输入输出示例

示例 1

函数参数

[
  [
    {
      "type": "add",
      "id": "a",
      "title": " Write "
    }
  ]
]

返回值

[
  {
    "id": "a",
    "title": "Write",
    "completed": false
  }
]
示例 2

函数参数

[
  [
    {
      "type": "add",
      "id": "a",
      "title": "A"
    },
    {
      "type": "toggle",
      "id": "a"
    }
  ]
]

返回值

[
  {
    "id": "a",
    "title": "A",
    "completed": true
  }
]
示例 3

函数参数

[
  []
]

返回值

[]
Practice has no points, deadline or submission cap. Use AI and search freely. Sign in to run public examples, or verify locally.

58 / 20,000字符

Add your test · optional

Enter a JSON argument array in actions order. Your test runs alongside the three examples.

Save both files in one folder and run this command with Node.js. Read the checks field for individual example results.

node verify-task-reducer.mjs
문의하기

서비스명: 포트포올
문의는 운영자에게 이메일로 전송됩니다.

이메일과 문의 내용은 답변을 위해 운영자 및 메일 발송 서비스로 전송됩니다. 비밀번호·결제정보·민감한 개인정보는 입력하지 마세요.