Optimise further

This commit is contained in:
atomiks
2017-12-31 17:13:05 +11:00
parent 71422f5180
commit 3ef1d1dc36

View File

@ -5,14 +5,14 @@ of two pre-ratings and returns an array containing two post-ratings.
The winner's rating is the first element of the array.
Use `Math.pow()` and math operators to compute the expected score (chance of winning) of each opponent
and compute the change in rating for each. Omit the second argument to use the default K-factor of
and compute the new rating for each. Omit the second argument to use the default K-factor of
32, or supply a custom K-factor value.
```js
const elo = ([a, b], kFactor = 32) => {
const expectedScore = (self, opponent) => 1 / (1 + Math.pow(10, (opponent - self) / 400));
const [eA, eB] = [expectedScore(a, b), expectedScore(b, a)];
const newRating = (rating, index) => rating + kFactor * (index - (index ? eA : eB));
const newRating = (rating, i) =>
rating + kFactor * (i - (i ? expectedScore(a, b) : expectedScore(b, a)));
return [newRating(a, 1), newRating(b, 0)];
};
```