title: Similar curry functions producing different results
body: <p>I am learning functional javascript and I came across two different implementations of the curry function. I am trying to understand the difference between the two they seem similar yet one works incorrectly for some cases and correctly for other cases.</p>
  
  <p>I have tried interchanging the functions the one defined using es6 'const'
  works for simple cases but when using 'filter' to filter strings the results are incorrect, but with integers it produces the desired results.</p>
  
  <pre><code>
  //es6 
  //Does not work well with filter when filtering strings
  //but works correctly with numbers
  const curry = (fn, initialArgs=[]) =&gt; (
      (...args) =&gt; (
          a =&gt; a.length === fn.length ? fn(...a) : curry(fn, a)
      )([...initialArgs, ...args])
  );
  
  //Regular js
  //Works well for all cases
  function curry(fn) {
    const arity = fn.length;
  
    return function $curry(...args) {
      if (args.length &lt; arity) {
        return $curry.bind(null, ...args);
      }
  
      return fn.call(null, ...args);
    };
  }
  
  const match = curry((pattern, s) =&gt; s.match(pattern));
  const filter = curry((f, xs) =&gt; xs.filter(f));
  
  const hasQs = match(/q/i);
  
  const filterWithQs = filter(hasQs);
  console.log(filterWithQs(["hello", "quick", "sand", "qwerty", "quack"]));
  </code></pre>
  
  <pre><code>//Output:
    //es6:
      [ 'hello', 'quick', 'sand', 'qwerty', 'quack' ]
   //regular:
      [ 'quick', 'qwerty', 'quack' ]
  
  </code></pre>