Created
January 25, 2023 18:40
-
-
Save andrepiske/5d2d95348b2f8d3db02270b5f39ec86a to your computer and use it in GitHub Desktop.
GetPercentageRounds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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