AI Native challenges by level

Level 1 · Foundations · Data and input

Normalize profile inputs

Clean up strings and report invalid fields.

Problem statement

Write function solution(profiles). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. profiles is an array of {name:string,email:string,age:string|number}. Trim name and collapse consecutive whitespace to one space; trim and lowercase email; convert age with Number. name must be nonempty and have JavaScript length at most 60. email must match ^[^\s@]+@[^\s@]+\.[^\s@]+$. A blank age string is invalid; otherwise age must be an integer from 0 through 120. For each profile return {ok:true,value:{name,email,age}} when valid, or {ok:false,errors:[field names]} when invalid. Report all invalid fields in name,email,age order. Return results in input order. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.

Example input and output

Example 1

Function arguments

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

Return value

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

Function arguments

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

Return value

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

Function arguments

[
  []
]

Return value

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

73 / 20,000 characters

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
문의하기

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

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