From e093e132c3182f0fea70b9c1d70f8c57dc04c5d3 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 00:02:46 +1100 Subject: [PATCH] simplify newRating function --- snippets/elo.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/snippets/elo.md b/snippets/elo.md index 5be73476f..1c52db62b 100644 --- a/snippets/elo.md +++ b/snippets/elo.md @@ -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 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 === 0 ? 1 : 0) - (index === 0 ? eA : eB)); - return [newRating(a, 0), newRating(b, 1)]; + const newRating = (rating, index) => rating + kFactor * (index - (index ? eA : eB)); + return [newRating(a, 1), newRating(b, 0)]; }; ```