Guest User

Untitled

a guest
Jun 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. irb(main):017:0> def flatten(lst)
  2. irb(main):018:1> if lst.empty?
  3. irb(main):019:2> lst
  4. irb(main):020:2> elsif lst.first.is_a? Array
  5. irb(main):021:2> flatten(lst[0]) + flatten(lst[1..-1])
  6. irb(main):022:2> else
  7. irb(main):023:2* [].push(lst[0]) + flatten(lst[1..-1])
  8. irb(main):024:2> end
  9. irb(main):025:1> end
Add Comment
Please, Sign In to add comment