Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created September 30, 2013 22:11
Show Gist options
  • Save ahimmelstoss/6771065 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6771065 to your computer and use it in GitHub Desktop.
fruit_array = ["apple", "pear", "orange", "banana", "apple", "peach", "Apple"]
def apple_picker(array)
array.select { |fruit| fruit.downcase == "apple" }
end
apple_picker(fruit_array)
#Implement it with collect and then implement it with select.
#Write a sentence about how select differs from collect.
#collect not possible as it returns an array of equal size
#Select returns a new array of all of the elements that return true given the block iterated over the elements.
#Collect returns a new array of equal value of elements with the block iterated over the elements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment