Created
November 21, 2019 17:23
-
-
Save venelrene/be8ac216f07134d233c5b5a065bd23d1 to your computer and use it in GitHub Desktop.
You have to write a function printer_error which given a string will output the error rate of the printer as a string representing a rational whose numerator is the number of errors and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.
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
| def printer_error(s) | |
| "#{s.count('n-z')}/#{s.size}" | |
| end | |
| ##### Before refactor ##### | |
| def printer_error(s) | |
| error_num = s.split('').count {|s| s =~ /[n-z]/} | |
| "#{error_num}/#{s.size}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment