From: Tom Verbeure Date: 2008-11-12T15:42:23+09:00 Subject: Re: 1.upto(4) in ruby 1.8.6 On Nov 11, 10:13 pm, Peņa, Botp wrote: > From: Tom Verbeure [mailto:hom...@gmail.com] > # indices     = 1.upto(points.size) > # zipped = indices.zip(distances, points) > >   (1..points.size).zip(distances,points) > > but arrays have builtin indices, why not > >   distances.zip(points) > > ? In later steps, the list gets sorted by the 'distance' field, then truncated and then sorted back in the original order, but with some inside points removed. Like this: indices = (1..points.size).to_a zipped = indices.zip(distances, points) zipped = zipped.delete_if { |x| x[1].nil? } zipped.sort! { |x,y| y[1] <=> x[1] } zipped = zipped.slice(0, max_nr_points) # Sort back in original order zipped.sort! { |x,y| x[0] <=> y[0] } points = zipped.collect { |p| p[2] } Tom