問題文
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
}
]