title: Frustrating recursive functions in JS
body: <p>I've been wracking my brain on this all day, and I still don't get it. Could someone please explain to me, how on earth does this function work?!?!?!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function findSolution(target) {
    function find(current, history) {
      if (current == target) {
        return history;
      } else if (current &gt; target) {
        return null;
      } else {
        return find(current + 5, `(${history} + 5)`) ||
          find(current * 3, `(${history} * 3)`);
      }
    }
    return find(1, "1");
  }
  
  console.log(findSolution(24));
  // → (((1 * 3) + 5) * 3)</code></pre>
  </div>
  </div>
  </p>
  
  <p>How does it not keep going back and forth calling on itself in an infinite loop?</p>