Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save tomcha/2fb39c4c001e6158dcc959088a47f0de to your computer and use it in GitHub Desktop.
recursion13.rb
list = [1, 2, 3, 4, 5, 6]
pro = Proc.new{|i| i % 2 == 0 ? true : false}
def filter(list, pro)
@newlist ||= []
if list.size == 0
@newlist
else
i = list.shift
@newlist << i if pro.call(i)
filter(list, pro)
end
end
p filter(list, pro)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment