문제

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

도움이 되었습니까?

해결책

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

[[9, 15], [], []].flatten
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top