Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from jacferreira/rounded_percentages.rb
Created October 31, 2018 07:38
Show Gist options
  • Save bogdanRada/3fa72cd2e9b1b870f4769fa556c6c2cf to your computer and use it in GitHub Desktop.
Save bogdanRada/3fa72cd2e9b1b870f4769fa556c6c2cf to your computer and use it in GitHub Desktop.
dataset = [18.562874251497007, 20.958083832335326, 18.562874251497007, 19.161676646706585, 22.75449101796407]
diff = 100 - dataset.map(&:floor).reduce(&:+)
rounded_percentages = dataset
.sort_by { |x| x.floor - x}
.map
.with_index { |e, index| index < diff ? e.floor + 1 : e.floor }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment