Most efficient way to write Combination and Permutation calculator in Javascript

前端 未结 5 972
闹比i
闹比i 2021-01-12 10:05

I have a math website http://finitehelp.com that teaches students Finite Math. I thought it would be cool to include a calculator so I made one for combinations and permutat

5条回答
  •  既然无缘
    2021-01-12 11:03

    As we know, combinations is short for:

    So the fastest combinations implement is below:

    function factorial(n) {
      let r = 1;
      while (n > 1) r *= n--;
      return r;
    }
    function combinations(n,r){
        let s = 1;
        let i = r;
        while(i

提交回复
热议问题