title: Javascript function challenge add(1,2) and add(1)(2) both should return 3
body: <p>A friend of mine challenged me to write a function that works with both of these scenarios</p>
  
  <pre><code>add(2,4)  // 6
  add(2)(4) // 6
  </code></pre>
  
  <p>My instinct was the write an add() function that returns itself but I'm not sure I'm heading in the right direction.  This failed.</p>
  
  <pre><code>function add(num1, num2){
      if (num1 &amp;&amp; num2){
          return num1 + num2;
      } else {
          return this;
      }
  }
  
  alert(add(1)(2));
  </code></pre>
  
  <p>So I started reading up on functions that return other functions or return themselves.</p>
  
  <ul>
  <li><a href="http://davidwalsh.name/javascript-functions" rel="nofollow noreferrer">http://davidwalsh.name/javascript-functions</a></li>
  <li><a href="https://stackoverflow.com/questions/17235259/javascript-self-calling-function-returns-a-closure-what-is-it-for">JavaScript: self-calling function returns a closure. What is it for?</a></li>
  <li><a href="https://stackoverflow.com/questions/17235259/javascript-self-calling-function-returns-a-closure-what-is-it-for">JavaScript: self-calling function returns a closure. What is it for?</a></li>
  </ul>
  
  <p>I am going to keep trying, but if someone out there has a slick solution, I'd love to see it!</p>