Created
October 11, 2013 16:06
-
-
Save irmiller22/6937472 to your computer and use it in GitHub Desktop.
apple_picker.rb
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
def apple_picker(array) | |
array.select do |x| | |
x == "apple" | |
end | |
end | |
def apple_picker(array) | |
test = [] | |
array.collect do |x| | |
test.push(x) if x.include?("apple") | |
end | |
test | |
end | |
# Select returns the values in the array that pass the evaluator in the block ==> ["apple", "apple"] | |
# Collect returns the true/false values in the array depending on the evaluator result ==> [true, false, true] | |
apple_picker(["apple", "orange", "apple"]) | |
def apple_picker_select(fruit) | |
fruit.collect {|x| x if x == "apple"}.compact | |
end | |
def apple_picker_each(fruit) | |
apples = [] | |
fruits.each do |x| | |
apples << x if x == "apple" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment