title: Trouble understanding Javascript nested function/closure
body: <p>I'm attempting to port the following JavaScript code to ruby:
  <a href="https://github.com/iguigova/snippets_js/blob/master/pokerIn4Hours/pokerIn4Hours.js" rel="nofollow">https://github.com/iguigova/snippets_js/blob/master/pokerIn4Hours/pokerIn4Hours.js</a></p>
  
  <p>I <em>think</em> I have most of it sorted, the function that is giving me grief is:</p>
  
  <pre><code>var kickers = function(idx){ // http://en.wikipedia.org/wiki/Kicker_(poker)        
      idx = idx || -15; 
      var notplayed = Math.max(input.length - 1/*player input*/ - 5, 0);
      return function(all, cardinality, rank) {
          return (all || 0) + (((cardinality == 1) &amp;&amp; (notplayed-- &lt;= 0)) ? rank * Math.pow(10, ++idx) : 0);
      };
  }();
  </code></pre>
  
  <p>And it is called further down like so:</p>
  
  <pre><code>k = kickers(k, cardsofrank[i], i);
  </code></pre>
  
  <p>I was wondering if someone could explain how this works in JavaScript. The fact that the inner function has 3 parameters and the outer only has 1 is confusing, especially given that it is called with 3 parameters. I would like to understand what it's trying to accomplish, so that I can port the code with confidence.</p>