Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JS Twitch chat listener voting script:
- var inputs = [
- {"username": "ShadowsDieAway", "input": "12 16"},
- {"username": "TheNewGeezer", "input": "5 24"},
- {"username": "YoYoYoDude1", "input": "24 16"},
- {"username": "ShadowsDieAway", "input": "11 11"},
- {"username": "TheNewGeezer", "input": "24 5"},
- {"username": "YoYoYoDude1", "input": "lol 16"},
- {"username": "ShadowsDieAway", "input": "5 5"},
- {"username": "TheNewGeezer", "input": "9 9"},
- {"username": "YoYoYoDude1", "input": "2 2"},
- {"username": "failure", "input": "lol hahaha"},
- {"username": "failure", "input": "3"},
- {"username": "failure", "input": "5 7 8"},
- {"username": "failure", "input": "nope"}
- ];
- var votes = [];
- var votes_x = {};
- var votes_y = {};
- function range_x(x) { return x >= 1 && x <= 25 };
- function range_y(y) { return y >= 1 && y <= 19 };
- function top_votes(type) {
- return Object.keys(type).sort( function(a,b) {
- return type[b] - type[a];
- }).map(function(x) {
- return x + ": " + type[x];
- });
- };
- inputs.forEach(function(input) {
- // parse
- var username = input["username"];
- var vote = input["input"].split(" ").map(function(x) { return parseInt(x,10); });
- // cull
- var usernames = votes.map(function(x) { return x[0] });
- // validation
- if ( !usernames.includes(username) && vote.length == 2 && range_x(vote[0]) && range_y(vote[1]) ) {
- votes.push([ username, vote[0], vote[1] ]);
- !votes_x[vote[0]] ? votes_x[vote[0]] = 1 : votes_x[vote[0]]++;
- !votes_y[vote[1]] ? votes_y[vote[1]] = 1 : votes_y[vote[1]]++;
- };
- });
- console.log(votes);
- console.log(top_votes(votes_x));
- console.log(top_votes(votes_y));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement