General smoothstep equation
<p>I saw this in Wikipedia: <a href="https://en.wikipedia.org/wiki/Smoothstep#Generalization_of_higher-order_equations" rel="nofollow noreferrer">Generalization of higher-order equations</a></p>

<p>My code when I tried to implement it:</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 generalSmoothStep(a, x) { //Generalized smoothstep
  var result = 0;
  for (var n = 0; n &lt; a - 1; n ++) {
    result += binom(-a, n) * binom(2 * a - 1, a - n - 1) * Math.pow(x, a + n);
  }
  return result;
}

function smoothStep(x) { //Normal smoothstep
  return -2 * Math.pow(x, 3) + 3 * Math.pow(x, 2);
  //I know about x * x * (3 - 2 * x);
}

function binom(a, b) { //Binomial coefficient
  return Math.factorial(a) / (Math.factorial(a-b) *  Math.factorial(b));
}

Math.factorial = function(value) { //Factorial
  var result = 1;
  if (value &gt; 0) {
    for (var count = 1; count &lt;= value; count ++) {
      result *= count;
    }
  } else if (value &lt; 0) {
    for (var count = -1; count &gt;= value; count --) {
      result *= count;
    }
  } else {
    result = 1;
  }
  return result;
};

document.getElementById("normalStep").innerHTML = "smoothStep(0.2) = " + smoothStep(0.2);
document.getElementById("generalStep").innerHTML = "generalSmoothStep(2, 0.2) = " + generalSmoothStep(2, 0.2);</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;head&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML"&gt;&lt;/script&gt;
  &lt;script&gt;
    MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
    });
  &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;p&gt;The function: $\operatorname{S}_a(x) = \sum_{n=0}^{a-1} \binom{-a}{n}\binom{2a - 1}{a - n - 1}x^{a + n}$&lt;/p&gt;
  
  &lt;p&gt;Here is the result when I run:&lt;/p&gt;
  
  &lt;p id="normalStep"&gt;&lt;/p&gt;
  &lt;p id="generalStep"&gt;&lt;/p&gt;
&lt;/body&gt;</code></pre>
</div>
</div>
</p>

<p>I know about binomial coefficient and factorial, but one problem is factorial can't use with negative number, so I tried to use tricks to bypass it, and failed...</p>

<p>And also the part with ()() chained together, I think it is multiplication ()*() between binom, and multiply with x^(a+n), as above, but it still not work.</p>

<p>Used google with words like: "general smooth step", "smooth step sum" but still not return any good explanation about it...</p>

<p>Anyone have any idea why my code not work, and also how to implement general smoothStep function in Javascript</p>