simplify newRating function

This commit is contained in:
atomiks
2017-12-31 00:02:46 +11:00
parent c7faf04ce0
commit e093e132c3

View File

@ -12,9 +12,8 @@ and compute the change in rating for each. Omit the second argument to use the d
const elo = ([a, b], kFactor = 32) => { const elo = ([a, b], kFactor = 32) => {
const expectedScore = (self, opponent) => 1 / (1 + Math.pow(10, (opponent - self) / 400)); const expectedScore = (self, opponent) => 1 / (1 + Math.pow(10, (opponent - self) / 400));
const [eA, eB] = [expectedScore(a, b), expectedScore(b, a)]; const [eA, eB] = [expectedScore(a, b), expectedScore(b, a)];
const newRating = (rating, index) => const newRating = (rating, index) => rating + kFactor * (index - (index ? eA : eB));
rating + kFactor * ((index === 0 ? 1 : 0) - (index === 0 ? eA : eB)); return [newRating(a, 1), newRating(b, 0)];
return [newRating(a, 0), newRating(b, 1)];
}; };
``` ```