group or count duplicated letters in elixir
<p>I'm trying to count duplicated letters on a String in Elixir.
I did try some attempts, but no success until now.</p>
<p>Let's take this string as example: <code>&quot;AAABBAAC&quot;</code></p>
<p>The desired output would be <code>&quot;3A2B2A1C&quot;</code>.</p>
<p>Converting this string to a <code>List</code>, I was able to count every letter, resulting in <code>&quot;5A2B1C&quot;</code>, but I have to count following the order.</p>
<p>This is the code I was doing:</p>
<pre><code>string
|&gt; String.graphemes
|&gt; Enum.reduce([], fn(letter, acc) -&gt; Keyword.update(acc, letter, 1, &amp;(&amp;1 + 1)) end)
</code></pre>
<p>But, in my tests, I'm trying to produce a List, like this <code>[&quot;AAA&quot;, &quot;BB&quot;, &quot;AA&quot;, &quot;C&quot;]</code>, so I can easely count with <code>String.lenght</code>.</p>
<p>Looks like using <code>Enum.chunk_by</code> I'm getting closer to a solution.</p>
<p>Is there a way to produce this?</p>