Array operation using map or collect in Ruby
-
21-12-2019 - |
문제
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
제휴하지 않습니다 StackOverflow