[Vit-discuss] Top Ruby Projects algorithm?

Todd Willey xtoddx at gmail.com
Fri Aug 25 16:12:49 EDT 2006


On 8/25/06, zdennis <zdennis at mktec.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The sum example with inject IMO is great...
>
>   numbers = 1, 3, 5, 7, 9, 11, 13, 15, 17
>   sum = numbers.inject( 0 ){ |sum,n| sum+=n }
>   puts "The sum is #{sum}!"

You don't need assignment when doing inject.
 so sum + n is sufficient.

>
> Zach
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFE71hiMyx0fW1d8G0RAsg4AJ9jWvjTMOV7FUrPrJ0/VTbRA1JgrQCfXIJp
> 1S0kyiHFOSl3ENGAsna8FjE=
> =iKCM
> -----END PGP SIGNATURE-----
> _______________________________________________
> vit-discuss mailing list
> vit-discuss at rubyforge.org
> http://rubyforge.org/mailman/listinfo/vit-discuss
>


More information about the vit-discuss mailing list