On Wed, Mar 12, 2008 at 6:13 PM, Todd Benson <caduceass / gmail.com> wrote: > On Wed, Mar 12, 2008 at 1:56 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote: > > > > This is faster than all the solutions posted so far: > > > > > > a = ['one.jpg', 'two.kzv', 'a.txt', 'a.az'] > > new_a = [1] > > > > for elmt in a > > if elmt[-3] == ?t > > new_a[0] = elmt > > else > > new_a << elmt > > end > > end > > > > --output:-- > > ["a.txt", "one.jpg", "two.kzv", "a.az"] > > Fast and somewhat of an eyesore. Doesn't work if there's more than > one text file. > > About the same speed and more rubyish... > > > a = ['one.jpg', 'two.kzv', 'a.txt', 'a.az'] > t = Time.now > new_a = [] > for elmt in a > (a.unshift elmt && a.pop) if elmt[-3] == ?t > end > puts a I reply to myself too often on this board. That won't work either, because it won't preserve the array contents. Todd