Created
November 9, 2020 08:06
-
-
Save mattmazzola/58c81b1211c3b1bb0aa0fe79ad5d9573 to your computer and use it in GitHub Desktop.
Next Rating
This file contains hidden or 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
type NextRatingFn = (rating: number, actualPoints: number, expectedPoints: number) => [nextRating: number, ratingChange: number] | |
type KFactorFunction = (rating: number) => number | |
function createNextRatingFn(kFactor: number | KFactorFunction): NextRatingFn { | |
const kFactorFn: KFactorFunction = typeof kFactor === 'number' | |
? () => kFactor | |
: kFactor | |
return (rating: number, actualPoints: number, expectedPoints: number): [number, number] => { | |
const change = Math.round(kFactorFn(rating) * (actualPoints - expectedPoints)) | |
const nextRating = rating + change | |
return [nextRating, change] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment