作者:消瘦了一生 | 来源:互联网 | 2023-05-18 16:42
HowdoIturnanArrayintoaHashwithvaluesof0withoutaneachloop.如何将数组转换为具有0值的散列,而不包含每个循环。
How do I turn an Array into a Hash with values of 0
without an each
loop.
如何将数组转换为具有0值的散列,而不包含每个循环。
For example, given this array:
例如,给定这个数组:
[1, 2, 3, 4]
I want to get this hash:
我想要得到这个散列:
{"1"=>0, "2"=>0, "3"=>0, "4"=>0}
4 个解决方案