domingo, 17 de julio de 2011

Ruby VS C#


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

No hay comentarios:

Publicar un comentario