Last active
July 22, 2016 15:24
-
-
Save tayfunerbilen/bcdf8c9bb01e7b373ad273cdea6f3b1a to your computer and use it in GitHub Desktop.
Combinations_Calculator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function factorial(number){ | |
var value = number; | |
for ( var i = number; i > 1; i-- ){ | |
value *= i - 1; | |
} | |
return value; | |
}; | |
function combination(n, r){ | |
if ( n == r ) return 1; | |
return factorial(n) / (factorial(r) * factorial(n - r)); | |
}; | |
// usage | |
alert( combination(10,5) ); // 252 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment