Created
September 30, 2013 22:10
-
-
Save ivanbrennan/6771053 to your computer and use it in GitHub Desktop.
Apple Picker
This file contains hidden or 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) | |
| 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