Skip to content

Instantly share code, notes, and snippets.

@anhdiepmmk
Created July 28, 2022 13:20
Show Gist options
  • Save anhdiepmmk/89165ac9be1696aa7c29fdb5438e7223 to your computer and use it in GitHub Desktop.
Save anhdiepmmk/89165ac9be1696aa7c29fdb5438e7223 to your computer and use it in GitHub Desktop.
const _ = require("lodash");
const fs = require("fs");
const teams = [
{ name: "Phap", weight: 5, rank: 5 },
{ name: "Duc", weight: 3, rank: 5 },
{ name: "Bo dao nha", weight: 2, rank: 5 },
];
const list = _.chain(teams)
.flatMap((team) => Array(team.weight).fill(team.name))
.shuffle()
.value();
function getRandomTeam() {
return _.sample(list);
}
const reports = [];
_.forEach(_.range(1, 1000000 + 1, 1), (idx) => {
const name = getRandomTeam();
reports.push({
turn: idx,
name,
});
});
console.log(reports.length);
_.forEach(teams, (team) => {
const filteredReports = _.filter(
reports,
(report) => report.name === team.name
);
const percent = _.round((filteredReports.length / reports.length) * 100, 2);
console.log(team.name, filteredReports.length, `${percent}%`);
});
fs.writeFileSync("./report.json", JSON.stringify(reports));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment