Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Created April 21, 2016 22:10
Show Gist options
  • Save Loschcode/a6bcefaa5d12c1aef810e47e2c7d5337 to your computer and use it in GitHub Desktop.
Save Loschcode/a6bcefaa5d12c1aef810e47e2c7d5337 to your computer and use it in GitHub Desktop.
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