Why Ruby inject method cannot sum up string lengths without initial value?

前端 未结 3 979
说谎
说谎 2020-12-18 06:39

Why the following code issues an error ?

[\'hello\',\'stack\',\'overflow\'].inject{|memo,s|memo+s.length}

TypeError: can\'t convert Fixnum into String
              


        
3条回答
提交回复
热议问题