Sha256: 645bf749e61e7afaf9a2870126662c86a7bcb18d670247b471d7deb8531b0bc6
Contents?: true
Size: 431 Bytes
Versions: 15
Compression:
Stored size: 431 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
15 entries across 15 versions & 2 rubygems