[英]Is there a way to perform if-else using collect in ruby and update an array
[英]Array operation using map or collect in Ruby
我有一個數組@a = [[9, 15], [], []]
我需要使用map方法使其[9,15]。 怎么可能?
我已經嘗試過以下聲明,
@a.map{|array| array.collect{|element| element} if array.any?}.compact
但是給[[9,15]]作為輸出。 誰能幫我。 謝謝 :)-
我不確定要求,但這可以達到預期的效果
[[9, 15], [], []].flatten
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.