ary = %w(foo bar baz quux pepe toto juan)
ary.select {|e| ary.index(e) % 4 == 0 } #=> ["foo", "pepe"]Lo "malo" es que necesitas una referencia al objeto. 2009/9/24 Gaston Ramos <[email protected]>: > El Thu, 24 de Sep de 2009, a las 01:56:05PM -0300, p8queen dijo: >> Gracias. Por las respuestas. Va de nuevo el enunciado. >> >> La solucion no son los indices, sino los valores cuyos indices sean >> congruentes a 0 modulo 4 >> ejemplo: >> dado c = %w{diego luis wilson santiago leandro lucas mariana paula >> analia fernando marcela} >> salida --> diego, leandro, analia >> > así de una: > > result = [] > c.each_with_index{|n, i| result << n if i % 4 == 0} > > a lo mejor hay una forma más corta. >> >> PD: en otro lenguaje la solucion es c[::4] >> >> -- >> gustavo c >> _______________________________________________ >> Ruby mailing list >> [email protected] >> http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar > > -- > "I always thought Smalltalk would beat Java, I just didn't know it would be > called 'Ruby' when it did." > > (Kent Beck) > > > +-------------------------------------+ > Gastón Ramos > http://gastonramos.com.ar/ > GNU/Linux Counter user #450312 > _______________________________________________ > Ruby mailing list > [email protected] > http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar > _______________________________________________ Ruby mailing list [email protected] http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
