Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var winnerArr = [];
- var hisArray = [];
- values = elec2000;
- getWinner(values, "state_name");
- function getWinner(values, key_name){
- var valueArr = values.map(function(item){ return item[key_name] });
- var isDuplicate = valueArr.some(function(item, idx){
- isTrue = valueArr.indexOf(item) != idx
- if (isTrue === true){
- itemname = item;
- var obj = [];
- thisRe = values.some(function(item, idx){
- if (item[key_name] === itemname){
- obj.push(item)
- }
- })
- max = Math.max.apply(Math,obj.map(function(o){return o.tab_votes}))
- for (x = 0; x < obj.length; x++){
- if (obj[x].tab_votes === max){
- sname = obj[x].state_name.toProperCase();
- if (obj[x].Party_Id === "Rep"){
- partyName = "R"
- } else if (obj[x].Party_Id === "Dem"){
- partyName = "D"
- }
- matchAbbrevToName.forEach(function(h){
- if (h.name === sname){
- lname = h.abbrev
- }
- });
- var w = {
- state: lname,
- party: partyName
- }
- winnerArr.push(w)
- }
- }
- }
- });
- winnerArr.forEach(function(t){
- stateParam = t.state + '=' + t.party;
- hisArray.push(stateParam)
- })
- var his_data = {
- myMap: hisArray.toString().replace(/,/g, '|')
- };
- console.log(his_data)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement