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
[]