function getChoseDishes(arr, numObjects = 3) {
const selectedObjects = [];
while (selectedObjects.length < numObjects) {
const randomIndex = Math.floor(Math.random() * arr.length);
const randomObject = arr[randomIndex];
if (!selectedObjects.includes(randomObject) && randomObject) {
selectedObjects.push(randomObject);
}
}
return selectedObjects
}
const meatStr = '花甲粉丝、鱼香肉丝、宫保鸡丁、水煮肉片、麻婆豆腐、回锅肉、口水鸡、香辣虾、辣子鸡、肉末茄子、辣椒炒肉'
const halfMeatStr = '孜然香肠土豆丁、番茄炒鸡蛋、青椒炒火腿鸡蛋'
const vageStr = '土豆丝、空心菜、红苕颠儿、干煸四季豆、酸辣包菜'
const soupStr = '番茄鸡蛋汤、黄瓜肉片汤'
const allDishes = {
"meatDishes": meatStr.split('、'),
"halfMeatDishes": halfMeatStr.split('、'),
"vageDishes": vageStr.split('、'),
"soupDishes": soupStr.split('、')
}
const eatChooses = [
{
type: 'meatDishes',
number: 1,
},{
type: 'halfMeatDishes',
number: 0,
},{
type: 'vageDishes',
number: 1,
},{
type: 'soupDishes',
number: 1,
}
]
let chooses = []
eatChooses && eatChooses.map(eat => {
if(eat.number) {
chooses = chooses.concat(getChoseDishes(allDishes[eat.type], eat.number))
}
})
console.log('今天吃:' + chooses.join('、') + '!')