US election margins since Ronald Reagan

node v4.9.1
version: master
endpointsharetweet
// "I guess it was the biggest electoral college win since Ronald Reagan" // - Donald Trump 2017-02-16 // on the subject of his 2016 election victory. // Let's look at the facts: var elections = { "2016 Trump": { college: [304, 227, 7], popularvote: 46.0 }, "2012 Obama": { college: [332, 206, 0], popularvote: 51.1, }, "2008 Obama": { college: [365, 173, 0], popularvote: 52.9, }, "2004 Bush": { college: [286, 252, 0], popularvote: 50.7 }, "2000 Bush": { college: [271, 266, 0], popularvote: 47.9 }, "1996 Clinton": { college: [379, 159, 0], popularvote: 49.2 }, "1992 Clinton": { college: [370, 168, 0], popularvote: 43.0 }, "1988 Bush": { college: [468,111,1], popularvote: 53.4 }, "1984 Reagan": { college: [525,13,0], popularvote: 58.8 } }; // calculate margin of victory by election var margins = []; for(var i in elections) { var margin = elections[i].college[0] - (elections[i].college[1] + elections[i].college[2]); var obj = { election: i, margin: margin }; margins.push(obj); } // margins by election margins.map(function(m) { return m.election + ' - ' + m.margin});
// so it wasn't the biggest. Where does it rank? // sort into "biggest margin first" order function compare(a, b) { if (a.margin > b.margin) { return -1; } if (a .margin < b.margin) { return 1; } // a must be equal to b return 0; } margins.sort(compare); margins.map(function(m) { return m.election + ' - ' + m.margin});
// so Trump's victory margin is the third smallest since Reagan. Five other elections were won by a larger margin // what about the popular vote then? var popularvotes = {}; var j = 0; for(var i in elections) { popularvotes[i] = elections[i].popularvote; } popularvotes
// only one President since Reagan had a smaller proportion of the popular vote, which was Bill Clinton in 1992 when Ross Perot, a third-party candidate, took 18.9% of the vote.
Loading…

no comments

    sign in to comment