test
Some checks are pending
continuous-integration/drone/push Build is running

This commit is contained in:
mol
2023-12-14 13:48:52 +08:00
parent b1709958e4
commit 164b6fa28e
3 changed files with 9 additions and 3 deletions

View File

@ -1,18 +1,23 @@
import getDb from '../db/index.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) {
const index = Math.floor(Math.random() * len);
logger(`index: ${index}`)
if (!indexList.has(index)) {
indexList.set(index);
list.push(data[index]);
}
}
logger(list.length)
return list;
}