Skip to content

Instantly share code, notes, and snippets.

@hoanga
hoanga / myflat.rb
Last active January 25, 2020 04:59
#!/usr/bin/env ruby
# https://gist.github.com/hoanga/4955d1da5479dbff12c3eb33b9d26107
# Returns a flattened version of all elements in the array. Same as Array.flatten
def my_flatten(arr)
result = []
arr.each do |elem|
if elem.kind_of?(Array)
result.concat(my_flatten(elem))