Pergunta

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

Foi útil?

Solução

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

[[9, 15], [], []].flatten
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top