Correct comment documenting mode aggday tiebreaker #338
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was trying to figure out what tie-breaker is used for the
modeaggday. I went looking in the code, and found this comment:road/src/butil.js
Lines 622 to 624 in e5fa3c7
(Fair enough to say that that no one cares about the
modeaggday; but I need to care if I'm writing code that I want to be compatible with the way Beeminder does it.)The comment does not accurately describe what the javascript function does.
What the current implementation actually does is break ties in favor of the one whose final occurrence appears first in the list. 1 appears in
[1, 2, 2, 1]before 2 does, but the final occurrence of 2 comes before the final occurrence of 1.This can be fixed either by changing the implementation, or by changing the comment. I chose to change the comment, even though the behavior in question is somewhat awkward to describe properly. If you'd prefer I instead fix the behavior to match the comment, I could do that instead.
Sorry for nitpicking something that "literally no one cares about", as the comment alleges, but as I did in fact need to spend a few minutes puzzling about the behavior here, it's probably best if it were accurately documented. (Better to have no comment at all than one that wrongly describes how the code works!)