I have a multidimensional array something like this
[ [[]], [[1], [2]], [[1, 2]] ]
What's the best way to remove the empty array?
Right now I am just doing a array[1..-1]
to remove the first element but I would like a more reliable way to do it.
Flatten each array and if it has no elements in it, delete it.
arr = [ [[]], [[1], [2]], [[1, 2]] ]
arr = arr.delete_if { |elem| elem.flatten.empty? }
# => [[[1], [2]], [[1, 2]]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With