19 lines
403 B
JavaScript
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;
|
|
}
|