Skip to content

Instantly share code, notes, and snippets.

@tayfunerbilen
Last active July 22, 2016 15:24
Show Gist options
  • Save tayfunerbilen/bcdf8c9bb01e7b373ad273cdea6f3b1a to your computer and use it in GitHub Desktop.
Save tayfunerbilen/bcdf8c9bb01e7b373ad273cdea6f3b1a to your computer and use it in GitHub Desktop.
Combinations_Calculator.js
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