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

Version Path
ruby-ext-0.2.16 old/lib/RubyExt/array.rb
ruby-ext-0.2.15 old/lib/RubyExt/array.rb
ruby-ext-0.2.13 old/lib/RubyExt/array.rb
ruby-ext-0.2.12 old/lib/RubyExt/array.rb
ruby-ext-0.2.11 old/lib/RubyExt/array.rb
ruby-ext-0.2.10 old/lib/RubyExt/array.rb
ruby-ext-0.2.9 old/lib/RubyExt/array.rb
ruby-ext-0.2.8 old/lib/RubyExt/array.rb
ruby-ext-0.2.7 old/lib/RubyExt/array.rb
ruby-ext-0.2.6 old/lib/RubyExt/array.rb
ruby-ext-0.2.5 old/lib/RubyExt/array.rb
ruby-ext-0.2.4 old/lib/RubyExt/array.rb
ruby-ext-0.2.3 old/lib/RubyExt/array.rb
RubyExt-0.1.1 lib/RubyExt/array.rb
RubyExt-0.1.2 lib/RubyExt/array.rb