Files
mol-robot/plugins/cook/api/index.js
mol 901f127b8a
Some checks failed
continuous-integration/drone Build is failing
feat: v1.2.0
2023-12-13 18:54:37 +08:00

19 lines
403 B
JavaScript

import getDb from '../db/index.js';
export async function getRandomRecipe(limit = 5) {
const data = await getDb();
const len = data.length;
const list = [];
const indexList = new Set();
while (indexList.size === limit) {
const index = Math.floor(Math.random() * len);
if (!indexList.has(index)) {
indexList.set(index);
list.push(data[index]);
}
}
return list;
}