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

cheers,
Todd