Skip to content

Commit beb9bfe

Browse files
authored
Fix negative deltas (thanks @gabrielsroka)
1 parent f6e28fe commit beb9bfe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

election.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ function checkForChanges(json) {
6969

7070
function printState(newData, oldData) {
7171
if (oldData != null) {
72-
console.log(" Total Votes:", comma(newData.tv), "+" + comma(newData.tv - oldData.tv));
72+
var delta = newData.tv - oldData.tv
73+
console.log(" Total Votes:", comma(newData.tv), (delta > 0 ? "+" : "") + comma(delta));
7374
} else {
7475
console.log(" Total Votes:", comma(newData.tv));
7576
}
@@ -79,7 +80,8 @@ function printState(newData, oldData) {
7980

8081
newData.cand.forEach(function (candData) {
8182
if (oldData != null) {
82-
console.log(" " + candData.name + ":", comma(candData.votes), "(+" + comma(candData.votes - oldData.votes[candData.name]) + ")");
83+
var diff = candData.votes - oldData.votes[candData.name];
84+
console.log(" " + candData.name + ":", comma(candData.votes), (diff > 0 ? "(+" : "(") + comma(diff) + ")");
8385
if (newFirst == null) {
8486
newFirst = candData.votes;
8587
oldFirst = oldData.votes[candData.name];

0 commit comments

Comments
 (0)