Skip to content

Instantly share code, notes, and snippets.

@dmamills
Last active December 17, 2015 01:19
Show Gist options
  • Save dmamills/5527209 to your computer and use it in GitHub Desktop.
Save dmamills/5527209 to your computer and use it in GitHub Desktop.
Elo rating system in javascript, revealing module pattern.
var elo = (function(){
var k = 32;
function setKFactor(n){
k = n;
};
function getExpected(ratingA, ratingB){
return 1/ (1+Math.pow(10, ((ratingB-ratingA)/400)));
};
function updateRating(expected,actual,current){
return parseInt(current+k*(actual-expected),10);
}
return {
setKFactor:setKFactor,
getExpected:getExpected,
updateRating:updateRating
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment