Last active
December 17, 2015 01:19
-
-
Save dmamills/5527209 to your computer and use it in GitHub Desktop.
Elo rating system in javascript, revealing module pattern.
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
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