From d7a341afd0d0bd593e96fc39980256f9e13738f4 Mon Sep 17 00:00:00 2001 From: mol Date: Thu, 14 Dec 2023 13:52:46 +0800 Subject: [PATCH] test --- plugins/cook/api/index.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/plugins/cook/api/index.js b/plugins/cook/api/index.js index e815e9c..a12d353 100644 --- a/plugins/cook/api/index.js +++ b/plugins/cook/api/index.js @@ -1,23 +1,18 @@ import getDb from '../db/index.js'; +import logger from '#root/utils/logger.js' export async function getRandomRecipe(limit = 5) { logger(`随机${limit}个食谱`) const data = await getDb(); const len = data.length; - logger(len) const list = []; const indexList = new Set(); - - while (indexList.size === limit) { + while (indexList.size < limit) { const index = Math.floor(Math.random() * len); - logger(`index: ${index}`) if (!indexList.has(index)) { - indexList.set(index); + indexList.add(index); list.push(data[index]); } } - - logger(list.length) - return list; }