Frage

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 :)-

War es hilfreich?

Lösung

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

[[9, 15], [], []].flatten
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top