JSFiddle - React, Tailwind, and code Playground
by dying_sakura
JavaScript
const source = [
{
entryID: 1,
entryName: "player1",
weight: 1900,
class:[],
},
{
entryID: 2,
entryName: "player1",
weight: 1900,
class:[],
},
{
entryID: 3,
entryName: "player2",
weight: 1900,
class:[],
},
{
entryID: 4,
entryName: "player3",
weight: 1900,
class:[],
},
{
entryID: 5,
entryName: "player4",
weight: 1900,
class:[],
},
{
entryID: 6,
entryName: "player5",
weight: 1900,
class:[],
},
{
entryID: 7,
entryName: "player6",
weight: 1900,
class:[],
},
{
entryID: 8,
entryName: "player7",
weight: 1900,
class:[],
},
{
entryID: 9,
entryName: "player8",
weight: 1900,
class:[],
},
{
entryID: 10,
entryName: "player9",
weight: 1900,
class:[],
},
{
entryID: 11,
entryName: "player10",
weight: 1900,
class:[],
},
{
entryID: 12,
entryName: "player11",
weight: 1900,
class:[],
},
{
entryID: 13,
entryName: "player12",
weight: 1900,
class:[],
},
{
entryID: 14,
entryName: "player1",
weight: 1900,
class:[],
},
];
console.log(combine(source))
function combine(data = [], different = 0, maxGroupSize = 2) {
const groups = [], related = [], sortedData = [...data].sort((a, b) => a.weight -...