Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created October 11, 2013 16:06
Show Gist options
  • Save irmiller22/6937472 to your computer and use it in GitHub Desktop.
Save irmiller22/6937472 to your computer and use it in GitHub Desktop.
apple_picker.rb
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