title: JavaScript Algorithms question: how do I use recursion to solve such a combination problem?
body: <p>we have a digit letter map that looks like this</p>
  <pre class="lang-js prettyprint-override"><code>const digitsLetters = new Map([
      [&quot;2&quot;, ['a', 'b', 'c']],
      [&quot;3&quot;, ['d', 'e', 'f']],
      [&quot;4&quot;, ['g', 'h', 'i']],
      [&quot;5&quot;, ['j', 'k', 'l']],
      [&quot;6&quot;, ['m', 'n', 'o']],
      [&quot;7&quot;, ['p', 'q', 'r', 's']],
      [&quot;8&quot;, ['t', 'u', 'v']],
      [&quot;9&quot;, ['w', 'x', 'y', 'z']],
    ]);
  
  </code></pre>
  <p>The question asks us to return the all possible letter combinations that the number could represent. For example, if we have <code>&quot;23&quot;</code> then first digit <code>2</code> maps to <code>['a', 'b', 'c']</code> and second digit maps to <code>['d', 'e', 'f']</code> and we end up getting <code>[&quot;ad&quot;,&quot;ae&quot;,&quot;af&quot;,&quot;bd&quot;,&quot;be&quot;,&quot;bf&quot;,&quot;cd&quot;,&quot;ce&quot;,&quot;cf&quot;]</code>.</p>
  <p>I have found a way to produce such a combination between two arrays.</p>
  <pre class="lang-js prettyprint-override"><code>// this will output [&quot;ad&quot;,&quot;ae&quot;,&quot;af&quot;,&quot;bd&quot;,&quot;be&quot;,&quot;bf&quot;,&quot;cd&quot;,&quot;ce&quot;,&quot;cf&quot;]
  ['a', 'b', 'c'].map(char1 =&gt; ['d', 'e', 'f'].map(char2 =&gt; char1 + char2)).flat(2)
  </code></pre>
  <p>So I thought I could just recursively apply this algorithm for such digit until I hit the last one. I think it is doable. However I had a hard time implementing the solution. Can someone please help me?</p>