Skip to content

Instantly share code, notes, and snippets.

@andrepiske
Created January 25, 2023 18:40
Show Gist options
  • Select an option

  • Save andrepiske/5d2d95348b2f8d3db02270b5f39ec86a to your computer and use it in GitHub Desktop.

Select an option

Save andrepiske/5d2d95348b2f8d3db02270b5f39ec86a to your computer and use it in GitHub Desktop.
GetPercentageRounds
# That damn GetPercentageRounds function I keep seeingin LinkedIn and Twitter
# but in ruby, refactored, without telling why or whether is morally good or bad.
# Just a function.
def GetPercentageRounds(v)
x = [10, [0, (10 * v).to_i].max].min
'πŸ”΅' * x +('βšͺ️' * (10 - x))
end
# irb(main):053:0> bar(0.1)
# => "πŸ”΅βšͺ️βšͺ️βšͺ️βšͺ️βšͺ️βšͺ️βšͺ️βšͺ️βšͺ️"
# irb(main):054:0> bar(0.67)
# => "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺ️βšͺ️βšͺ️βšͺ️"
# irb(main):055:0> bar(1)
# => "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅"
# irb(main):056:0> bar(2)
# => "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment