Created
April 21, 2016 22:10
-
-
Save Loschcode/a6bcefaa5d12c1aef810e47e2c7d5337 to your computer and use it in GitHub Desktop.
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
require 'pry' | |
module ArrayFiltering | |
module_function | |
FILTERS = [3,5,6,7] | |
def process(string) | |
string.split(',').map(&:to_i).reject(&:zero?).map do |i| | |
return [] if all_or_none?(i) | |
in_available_filters(i) | |
end.compact | |
end | |
private | |
def all_or_none?(i) | |
(i == -1 || i == -2) ? true : false | |
end | |
def in_available_filters?(i) | |
i if FILTERS.include? i | |
end | |
end | |
ArrayFiltering.process('0,0,1,2,3') | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment