Created
July 4, 2019 16:40
-
-
Save manojnaidu619/42e077a76f07101b62f8b079b9cdb3cc to your computer and use it in GitHub Desktop.
Ruby Different way of sorting array!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nums = [5,4,3,2,1,1] | |
a = Array.new | |
until nums.empty? | |
min = nums.min | |
step = nums.count(min) | |
if step > 1 | |
step.to_i.times do | |
a << min | |
end | |
nums.delete(min) | |
else | |
a << nums.min | |
nums.delete(min) | |
end | |
end | |
p a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment