Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created June 23, 2016 03:29
Show Gist options
  • Select an option

  • Save tomcha/dba8a145a0a834b3f8ce540ba268ba9d to your computer and use it in GitHub Desktop.

Select an option

Save tomcha/dba8a145a0a834b3f8ce540ba268ba9d to your computer and use it in GitHub Desktop.
recursion12.rb
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