test.js 729 字节
Newer Older
杨龙伟 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
const fs = require("fs");

// 测试抽奖结果数据的正确性
var selected = {},
  repeat = [],
  luckyData = require("/Users/xiechang/Documents/project/抽奖/product/dist/temp.json"),
  errorData = require("/Users/xiechang/Documents/project/抽奖/product/dist/error.json");

for (let key in luckyData) {
  let item = luckyData[key];
  item.forEach(user => {
    let id = user[0];
    if (selected[id]) {
      repeat.push(user[1]);
      return;
    }
    selected[id] = true;
  });
}

errorData.forEach(user => {
  let id = user[0];
  if (selected[id]) {
    repeat.push(user[1]);
    return;
  }
  selected[id] = true;
});

if (repeat.length > 0) {
  console.log(repeat);
  return;
}
console.log("没有重复选项");