AI Native 分级编程挑战

第1级 · 基础 · 数据与输入

规范化用户输入

清理字符串并找出无效字段。

题目说明

编写 function solution(profiles)。输入输出均为 JSON 值,不要修改输入数组或对象。不支持外部库、网络访问及异步函数。 profiles 是 {name:string,email:string,age:string|number} 数组。对 name 执行 trim 并把连续空白合并为一个空格;对 email 执行 trim 并转小写;用 Number 转换 age。name 非空且 JavaScript length 不超过60;email 必须匹配 ^[^\s@]+@[^\s@]+\.[^\s@]+$。空白 age 字符串无效,其余 age 必须是0至120的整数。有效时返回 {ok:true,value:{name,email,age}};无效时返回 {ok:false,errors:[字段名]}。按 name,email,age 顺序列出所有错误字段,结果数组保留输入顺序。 输入范围:每个输入数组最多50,000项,每个字符串最多1,000个字符。数字必须有限,整数及整数累计结果在JavaScript安全整数范围内。其他类型和有效性遵循上述规则。

输入输出示例

示例 1

函数参数

[
  [
    {
      "name": "Alex",
      "email": "alex@example.com",
      "age": 20
    }
  ]
]

返回值

[
  {
    "ok": true,
    "value": {
      "name": "Alex",
      "email": "alex@example.com",
      "age": 20
    }
  }
]
示例 2

函数参数

[
  [
    {
      "name": "  Alex   Kim ",
      "email": " A@EXAMPLE.COM ",
      "age": "42"
    }
  ]
]

返回值

[
  {
    "ok": true,
    "value": {
      "name": "Alex Kim",
      "email": "a@example.com",
      "age": 42
    }
  }
]
示例 3

函数参数

[
  []
]

返回值

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

59 / 20,000字符

Add your test · optional

Enter a JSON argument array in profiles 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-normalize-profiles.mjs
문의하기

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

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