/**
每个人匹配一个不重复的职位
如果一人多职或者一职多人
-
集合增加数量即可
*/
function run() {
//所有人
var l1 = ["赵","钱","孙","李","周","吴","郑","王","冯","陈"]
//所有职位
var l2 = ["立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒"]
//随机匹配的职位
var l3 = [];for (let i = 0; i < l1.length; i++) {
// 生成1到10之间的随机整数
var num = Math.floor(Math.random() * l2.length);
let name = l1[i]
let job = l2[num]
l3.push({
"id": i,
"name": name,
"job": job
});
l2.splice(num, 1);//删除已取出的职位
}
console.log("已匹配:", l3);
console.log("空余职位:",l2);
}
run()