0

I have an array @a = [[9, 15], [], []]

I need to make it [9,15] using map method. How it is possible?

I have tried the below statement,

@a.map{|array| array.collect{|element| element} if array.any?}.compact

But giving [[9,15]] as output. Can anyone just help me out. Thanks :)-

Rajesh Omanakuttan
  • 6,788
  • 7
  • 47
  • 85

1 Answers1

5

I'm not sure about the requirements, but this gives the desired result

[[9, 15], [], []].flatten
Ju Liu
  • 3,939
  • 13
  • 18