El *_*ino 2 ruby
无论如何,我可以计算数组中对象的平方和
a=[1,2,3,4] sum of square = 1+4+9+16
a=[1,2,3,4]
sum of square = 1+4+9+16
请我试着找到一种方法来做到这一点.
DNN*_*NNX 5
a.map{|x| x**2}.inject(0, &:+)
归档时间:
14 年,4 月 前
查看次数:
4347 次
最近记录:
8 年,3 月 前