Sha256: 9d63485fe6f95e7a4086576b36f4336741eeb12e250ccc4d99ddc09e24e00415
Contents?: true
Size: 501 Bytes
Versions: 2
Compression:
Stored size: 501 Bytes
Contents
class Array def sort_by_weight weight clone.sort_by_weight! weight.clone end def sort_by_weight! weight size.times do |i| iteration = size - i - 1 break if iteration < 0 iteration.times do |j| if weight[j] > weight[j+1] buf = self[j] self[j] = self[j+1] self[j+1] = buf buf = weight[j] weight[j] = weight[j+1] weight[j+1] = buf end end end return self end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-ext-0.4.1 | old/lib/RubyExt/array.rb |
ruby-ext-0.4.0 | old/lib/RubyExt/array.rb |