ELO snippet formatting + performance
Not assigning `arr.length` to a variable in a for loop means that the read is done on every iteration.
This commit is contained in:
committed by
GitHub
parent
e93869b72a
commit
b8695263ee
@ -15,17 +15,20 @@ const elo = ([...ratings], kFactor = 32, selfRating) => {
|
||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||
const newRating = (rating, i) =>
|
||||
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
||||
|
||||
if (ratings.length === 2) {
|
||||
return [newRating(a, 1), newRating(b, 0)];
|
||||
} else {
|
||||
for (let i = 0; i < ratings.length; i++) {
|
||||
}
|
||||
|
||||
for (let i = 0, l = ratings.length; i < l; i++) {
|
||||
let j = i;
|
||||
while (j < ratings.length - 1) {
|
||||
|
||||
while (j < l - 1) {
|
||||
[ratings[i], ratings[j + 1]] = elo([ratings[i], ratings[j + 1]], kFactor);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ratings;
|
||||
};
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user