Last active
March 29, 2021 18:29
-
-
Save analogrelay/84337a94a9c8563885ea2b34db529663 to your computer and use it in GitHub Desktop.
Ruby Pop Quiz
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
names = [ "aaron", "abbot", "betty", "brian" ] | |
def starts_with_a(name) | |
return name.start_with? "a" | |
end | |
puts "filtering" | |
def filter_by_method(a) | |
a.select { |n| starts_with_a n } | |
end | |
def filter_by_block(a) | |
a.select { |n| return n.start_with?("a") } | |
end | |
puts "filtered by method: #{filter_by_method(names)}" | |
puts "filtered by block: #{filter_by_block(names)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment