Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var candidateNames = ["Benjamin", "Donald", "George", "John", "Rutherford"];
- function getCandidates() {
- var first_scores = [0,0,0,0,0];
- var ranked_scores = [0,0,0,0,0];
- var ballots = window.location.hash.split("#")[1].split(",");
- console.log(ballots);
- for (var i = 0; i < ballots.length; i++) {
- var ballot = ballots[i];
- first_scores[ballot[0]] += 1;
- for (var j = 0; j < ballot.length; j++) {
- ranked_scores[ballot[j]] += 5 - j;
- }
- }
- // Extract actual first from firsts
- var first_max = -1;
- var first_idx = -1;
- for (var i = 0; i < first_scores.length; i++) {
- if (first_scores[i] > first_max) {
- first_max = first_scores[i];
- first_idx = i;
- }
- }
- console.log(first_idx);
- console.log(candidateNames[first_idx]);
- // Extract actual ranked max
- var ranked_max = -1;
- var ranked_max_idx = -1;
- for (var i = 0; i < ranked_scores.length; i++) {
- if (ranked_scores[i] > ranked_max) {
- ranked_max = ranked_scores[i];
- ranked_max_idx = i;
- }
- }
- console.log(ranked_max);
- console.log(candidateNames[ranked_max_idx]);
- }
- getCandidates()
Advertisement
Add Comment
Please, Sign In to add comment