title: Need help to understand an example of recursion
body: <p>I was trying to understand an example written in JavaScript. Actually, I'm reading the book <em>Eloquent JavaScript</em>, but got stuck while reading a topic about recursion.</p>
  
  <p>Here is the statement of the example:</p>
  
  <blockquote>
    <p>By starting from the number 1 and repeatedly either adding 5 or
    multiplying by 3, an infinite set of numbers can be produced. How
    would you write a function that, given a number, tries to find a
    sequence of such additions and multiplications that produces that
    number?</p>
  </blockquote>
  
  <p>Here is the code of the example:</p>
  
  <pre><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");
  }
  </code></pre>