<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ave Mujica Technology</title>
    <description>The latest articles on DEV Community by Ave Mujica Technology (@_a365abd8a5814ad1fb697).</description>
    <link>https://dev.to/_a365abd8a5814ad1fb697</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4033839%2F70ace1eb-aa39-4314-b59b-abbc14612fb5.png</url>
      <title>DEV Community: Ave Mujica Technology</title>
      <link>https://dev.to/_a365abd8a5814ad1fb697</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_a365abd8a5814ad1fb697"/>
    <language>en</language>
    <item>
      <title>Shuffle once, then deal: making balanced teams in JavaScript</title>
      <dc:creator>Ave Mujica Technology</dc:creator>
      <pubDate>Thu, 03 Dec 2026 03:52:55 +0000</pubDate>
      <link>https://dev.to/_a365abd8a5814ad1fb697/shuffle-once-then-deal-making-balanced-teams-in-javascript-4lm7</link>
      <guid>https://dev.to/_a365abd8a5814ad1fb697/shuffle-once-then-deal-making-balanced-teams-in-javascript-4lm7</guid>
      <description>&lt;p&gt;If you assign seven people to three teams by rolling a die for each person, the teams can end up with four, two, and one member. For a workshop, the useful guarantee is simple: team sizes differ by at most one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shuffle the list first
&lt;/h3&gt;

&lt;p&gt;In a small browser-based grouping tool, I read one name per line, trim whitespace, and drop blank lines. I check that the number of teams is an integer between one and the number of participants. Then I shuffle the entries with Fisher–Yates, choosing a random position from zero through the current index at each step. Identical display names still represent separate entries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deal one name to each team in turn
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;splitIntoGroups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shuffled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;groupCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;groups&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;groupCount&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;shuffled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;groupCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given the already shuffled order &lt;code&gt;[E, F, A, D, G, B, C]&lt;/code&gt;, the result is &lt;code&gt;[E, D, C]&lt;/code&gt;, &lt;code&gt;[F, G]&lt;/code&gt;, and &lt;code&gt;[A, B]&lt;/code&gt;. I checked the same seven-person, three-team case in the browser. Each full pass through the list of teams gives every team one person. The final partial pass can add at most one extra person per team.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep input and output on the page
&lt;/h3&gt;

&lt;p&gt;The tool runs the draw on the current page and puts the result on screen before offering a copy button. If the browser rejects clipboard access, the visible result still gives people something they can select and copy. Reloading clears the pasted list.&lt;/p&gt;

&lt;p&gt;This covers headcount. If you need to spread mentors across teams or keep pairs together, those constraints need their own assignment step.&lt;/p&gt;

&lt;p&gt;Disclosure: AI assisted with drafting this article. The grouping behavior was checked against the working browser example.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
