Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from toreriklinnerud/refactor-this.rb
Created October 8, 2010 16:17
Show Gist options
  • Save jcf/617050 to your computer and use it in GitHub Desktop.
Save jcf/617050 to your computer and use it in GitHub Desktop.
%w(red amber green).map.with_index do |color, index|
color if ((index + 1) / 3.0) < (count.to_f / total.to_f)
end.compact.first
@jcf
Copy link
Author

jcf commented Apr 20, 2013

Good times @toreriklinnerud. 😄

Wanna refactor this?

colors = %w(red amber green)
colors[(count.to_f / total) * colors.length]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment