Created
June 23, 2016 03:29
-
-
Save tomcha/dba8a145a0a834b3f8ce540ba268ba9d to your computer and use it in GitHub Desktop.
recursion12.rb
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
| list = [1, 2, 3, 4, 5] | |
| pro = Proc.new{|i| i * 2} | |
| class Map | |
| def self.map(list, pro) | |
| @newlist ||= [] | |
| if list.size == 0 | |
| @newlist | |
| else | |
| i = list.shift | |
| @newlist.push pro.call(i) | |
| map(list, pro) | |
| end | |
| end | |
| end | |
| p Map.map(list, pro) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment