Ruby equivalent of C# Linq Aggregate method
You have this code in C#:
var factorial = new[] { 1, 2, 3, 4, 5 }.Aggregate((acc, i) => acc * i)
And Ruby responses:
factorial = (1..5).reduce(:*)
or maybe
factorial = 1.upto(5).reduce(:*)
or
factorial = [1, 2, 3, 4, 5].reduce(:*)
More info:
http://stackoverflow.com/questions/5036836/ruby-equivalent-of-c-linq-aggregate-method
Comentarios
Publicar un comentario