close

a = [1,2,3,4]

b = a.map {|x| x*x }  #b=[1, 4, 9, 16]

c = a.select {|x| x%2==0 } #c=[2,4]

d=a.inject(0){|sum,x| sum+=x**2} #d=30

 

arrow
arrow
    全站熱搜

    igogo 發表在 痞客邦 留言(0) 人氣()