The Upvote That Counted Twice — JavaScript Bug Hunt

Inspired by vote-count drift on link aggregators. A user who taps up, then down, then up again must count as one final upvote — the tally is per user, last…

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Easy
  • Concepts: Dedupe, State
  • Modelled on: Reddit
  • Visible tests: one user's repeated upvotes count once; last action per user wins; independent users sum
  • Reward: 50 XP for a complete fix

Briefing

Inspired by vote-count drift on link aggregators. A user who taps up, then down, then up again must count as one final upvote — the tally is per user, last action wins.

The event fold in votes.js sums raw events instead.

Bug report

BUG-UPV2 · Reported by: ranking team

tally([u1:+1, u1:-1, u1:+1]) must be +1 (one user, final state up). We compute +1 -1 +1 = ... well, +1 — but tally([u1:+1, u1:+1]) gives +2, and rage-tappers are minting infinite karma.

Logs

[votes] post 991: 3 users, tally=17

The code as shipped

src/feed/votes.js (editable)

// Folds vote events into a score. dir is +1 or -1.
exports.tally = function (events) {
  var score = 0;
  for (var i = 0; i < events.length; i++) {
    score += events[i].dir;
  }
  return score;
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.