Last active
February 20, 2016 13:00
-
-
Save iamajvillalobos/bda4068b2173247eb32c to your computer and use it in GitHub Desktop.
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
age = [26, 27, 24] | |
friends = { mark: 26, christopher: 27, aj: 24 } | |
def reject(enumerable) | |
if enumerable.is_a? Array | |
results = [] | |
enumerable.each do |item| | |
results << item unless yield(item) | |
end | |
puts results.inspect | |
end | |
if enumerable.is_a? Hash | |
results = {} | |
enumerable.each do |name, age| | |
results[name] = age unless yield(name, age) | |
end | |
results | |
end | |
end | |
puts "using reject with array param" | |
puts reject(age) { |item| item > 26 } | |
puts "using reject with hash param" | |
puts reject(friends) { |name, age| age > 26} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment