forked from joystickinteractive/slack-vote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tally.js
27 lines (21 loc) · 794 Bytes
/
tally.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
_ = require('underscore');
var tally = {
printPoll: function(data) {
// the string that separates poll items when printing
separator = ' \n';
// build the output
pollResults = 'Current Poll: ' + data.pollName + ' ';
pollResults += '\nResults: \n';
_.each(data.answers, function(answer) {
formattedAnswerName = answer.answerName.capitalizeFirstLetter();
pollResults += formattedAnswerName + ': ' + answer.votes.length + separator;
});
// Remove the last separator (newline) to avoid extra empty line
lastIndexOfSeparator = pollResults.lastIndexOf(separator);
if (lastIndexOfSeparator > separator.length) {
pollResults = pollResults.substring(0, lastIndexOfSeparator);
}
return pollResults;
}
};
module.exports = tally;