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
# A simple implementation of character-based filtering in Ruby, covering different edge cases and use scenarios. | |
def filter_array(input) | |
# Filter array for numbers | |
num_array = input.select { |item| item =~ /\d/ } | |
# Filter array for capitals | |
capital_array = input.select do |item| | |
item =~ /^[A-Z]+$/ ? true : false | |
end.compact |