Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created January 5, 2012 17:47
Show Gist options
  • Save jashkenas/1566330 to your computer and use it in GitHub Desktop.
Save jashkenas/1566330 to your computer and use it in GitHub Desktop.
# Final Iowa vote counts.
results =
romney: 30015
santorum: 30007
paul: 26219
gingrich: 16251
perry: 12604
bachmann: 6073
huntsman: 745
nopref: 135
other: 117
cain: 58
roemer: 31
# Total votes.
total = 0
total += votes for name, votes of results
# Print percentages.
for name, votes of results
console.log name, votes / total * 100
# Prints:
#
# romney 24.551143102531594
# santorum 24.544599402887407
# paul 21.44615762136518
# gingrich 13.29270786470901
# perry 10.309598789415565
# bachmann 4.967485992392949
# huntsman 0.6093820293648522
# nopref 0.11042493149564436
# other 0.09570160729622511
# cain 0.04744182242035091
# roemer 0.025356836121222037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment