题目说明
编写 function solution(events, width)。输入输出均为 JSON 值,不要修改输入数组或对象。不支持外部库、网络访问及异步函数。 events:{timestamp:integer,service:string,durationMs:nonnegative integer,status:integer}[], width:positive integer. Bucket start=floor(timestamp/width)*width, including negative timestamps. Return {start,service,count,errors,totalMs} per bucket/service; errors counts status>=500. Sort by start, then case-sensitive JavaScript service ordering. All totals are safe integers. 输入范围:每个输入数组最多50,000项,每个字符串最多1,000个字符。数字必须有限,整数及整数累计结果在JavaScript安全整数范围内。其他类型和有效性遵循上述规则。
输入输出示例
示例 1
函数参数
[
[
{
"timestamp": 0,
"service": "api",
"durationMs": 10,
"status": 200
},
{
"timestamp": 9,
"service": "api",
"durationMs": 20,
"status": 500
},
{
"timestamp": 10,
"service": "api",
"durationMs": 10,
"status": 200
}
],
10
]返回值
[
{
"start": 0,
"service": "api",
"count": 2,
"errors": 1,
"totalMs": 30
},
{
"start": 10,
"service": "api",
"count": 1,
"errors": 0,
"totalMs": 10
}
]示例 2
函数参数
[
[
{
"timestamp": 3,
"service": "z",
"durationMs": 10,
"status": 200
},
{
"timestamp": 1,
"service": "a",
"durationMs": 10,
"status": 200
}
],
5
]返回值
[
{
"start": 0,
"service": "a",
"count": 1,
"errors": 0,
"totalMs": 10
},
{
"start": 0,
"service": "z",
"count": 1,
"errors": 0,
"totalMs": 10
}
]示例 3
函数参数
[
[
{
"timestamp": 0,
"service": "api",
"durationMs": 1,
"status": 503
}
],
100
]返回值
[
{
"start": 0,
"service": "api",
"count": 1,
"errors": 1,
"totalMs": 1
}
]