#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Flatten_a_list
#

func flatten(a) {
    var flat = []
    a.each { |item|
        flat << (item.kind_of(Array) ? __FUNC__(item)... : item)
    }
    return flat
}
 
var arr = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
say flatten(arr)      # used-defined function
say arr.flatten       # built-in method for Array obj
