問題文
function solution(documents, query, limit)を書いてください。入出力はJSON値です。入力配列やオブジェクトを変更しないでください。外部ライブラリ・ネットワーク・非同期関数は使えません。 documents:{id:string,vector:integer[]}[], query:integer[], limit:nonnegative integer. Vectors share dimension 1–32 with values -100…100. Cosine=dot/(product of magnitudes); use zero if either vector is zero. score=Math.round(cosine*1_000_000). Sort by rounded score descending, preserving input order on ties. Return top limit {id,score}; limit may exceed document count. 入力範囲:各入力配列は最大50,000項目、文字列は最大1,000文字です。数値は有限値で、整数と整数の合算結果はJavaScriptの安全な整数範囲内です。その他の型と有効性は上記の規則に従います。
入出力例
例 1
関数の引数
[
[
{
"id": "a",
"vector": [
1,
0
]
},
{
"id": "b",
"vector": [
0,
1
]
}
],
[
1,
0
],
2
]戻り値
[
{
"id": "a",
"score": 1000000
},
{
"id": "b",
"score": 0
}
]例 2
関数の引数
[
[
{
"id": "a",
"vector": [
1,
1
]
},
{
"id": "b",
"vector": [
2,
2
]
}
],
[
1,
1
],
1
]戻り値
[
{
"id": "a",
"score": 1000000
}
]例 3
関数の引数
[
[
{
"id": "a",
"vector": [
1,
0
]
},
{
"id": "b",
"vector": [
0,
1
]
},
{
"id": "c",
"vector": [
1,
0
]
}
],
[
1,
0
],
2
]戻り値
[
{
"id": "a",
"score": 1000000
},
{
"id": "c",
"score": 1000000
}
]