From addddbb8ccecf2052aea376538dffd6c5cf5e4a7 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 16 Feb 2023 09:03:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=9D=83=E9=87=8D=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/api/tool.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pages/api/tool.ts b/pages/api/tool.ts index 9c85632..b1b923d 100644 --- a/pages/api/tool.ts +++ b/pages/api/tool.ts @@ -78,8 +78,11 @@ export default async function handler( counts[smallestIndex][user][smallestIndex], ]); } - weightList.sort((a, b) => a[1] - b[1] || a[2] - b[2]); - // console.log("weightList", weightList); + // 相同工时数量、相同权重的情况下随机选择 + weightList.sort( + (a, b) => a[1] - b[1] || b[2] - a[2] || Math.random() - 0.5 + ); + console.log("weightList", smallestIndex, weightList); const theChoosenUser = weightList[0][0]; // console.log("theChoosenUser", theChoosenUser); // 记录结果