Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
Created September 30, 2013 22:10
Show Gist options
  • Select an option

  • Save ivanbrennan/6771053 to your computer and use it in GitHub Desktop.

Select an option

Save ivanbrennan/6771053 to your computer and use it in GitHub Desktop.
Apple Picker
def apple_picker(array)
apples_etc = array.collect { |element| element if element == "apple"}
apples_etc.compact
end
def apple_picker(array)
array.select {|element| element == "apple"}
end
# select returns an array of the original elements that make block evaluate to true, while
# collect returns an array of the block's return values for each original element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment