Skip to content

Instantly share code, notes, and snippets.

@uokesita
Created October 12, 2013 03:11
Show Gist options
  • Save uokesita/6945339 to your computer and use it in GitHub Desktop.
Save uokesita/6945339 to your computer and use it in GitHub Desktop.
1.8.7 :012 > obj = [34773, 28566, 31509, 24366, 32891, 32230, 29208, 24501, 32027, 31359, 27217, 31430, 28049, 35981, 34471, 33724, 30934, 35097, 29596, 31871, 31603, 33786, 33399]
=> [34773, 28566, 31509, 24366, 32891, 32230, 29208, 24501, 32027, 31359, 27217, 31430, 28049, 35981, 34471, 33724, 30934, 35097, 29596, 31871, 31603, 33786, 33399]
1.8.7 :013 > total = 718588
=> 718588
1.8.7 :014 > list = obj.map{ | x | 1-(x/total).to_f }
=> [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
1.8.7 :015 >
1.8.7 :016 >
1.8.7 :017 > list = obj.map{ | x | 1.0-(x/total) }
=> [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
1.8.7 :018 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment