Created
May 15, 2014 22:16
-
-
Save DiegoSalazar/5a186b35d69fb4e39d3c to your computer and use it in GitHub Desktop.
ESAAS HW0 Part 2
This file contains 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
# using string interpolation | |
def hello(name) | |
"Hello, #{name}" | |
end | |
# I first check if the first letter is alphabetical | |
# then see if the first lower case letter is a vowel | |
# and return the opposite of that boolean | |
def starts_with_consonant?(s) | |
return false unless s[/^[a-z]/i] | |
not %(a e i o u).include? s.downcase[0].to_s | |
end | |
# I do an empty string check first | |
# then I see if it's a valid binary representation by | |
# checking that all chars are either 1 or 0 | |
# finally I convert the string into integer using base 2 | |
# conversion, then a quick modulus check with 4, 0 means it | |
# its a multiple. | |
def binary_multiple_of_4?(s) | |
return false if s == '' | |
s.split('').uniq.all? { |i| i == '0' || i == '1' } \ | |
&& s.to_i(2) % 4 == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment