Here's an equivalent implementation of the Ruby flattenarray
class in Go:
main.go538 chars31 lines
The flatten
function takes an input array of type []interface{}
, which allows us to accept the variety of different types that Ruby arrays can contain. The function recursively flattens the nested arrays and discards nil values, similar to the Ruby implementation. Finally, the main
function demonstrates how to use the flatten
function with a sample input array.
gistlibby LogSnag