Class: Algorithmable::Sort::Shuffle
- Inherits:
-
Object
- Object
- Algorithmable::Sort::Shuffle
show all
- Extended by:
- Utils
- Defined in:
- lib/algorithmable/sort/shuffle.rb
Class Method Summary
collapse
Methods included from Utils
exchange, partition, swap
Class Method Details
.sort(collection) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/algorithmable/sort/shuffle.rb', line 6
def self.sort(collection)
return collection if collection.empty? || 2 > collection.length
collection.length.times do |i|
exchange(i, rand(i + 1), collection)
end
collection
end
|