Created
October 14, 2016 02:25
-
-
Save shirts/ebbc36de631f1005bec50c42c6c3c992 to your computer and use it in GitHub Desktop.
Custom Ruby sort implementation
This file contains 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
def sort(original) | |
sorted = [] | |
original.each do |original_num| | |
if sorted.empty? || original_num > sorted.last | |
sorted << original_num | |
next | |
else | |
sorted.each do |sorted_num| | |
if original_num <= sorted_num | |
sorted.insert(sorted.index(sorted_num), original_num) | |
break | |
end | |
end | |
end | |
end | |
sorted | |
end | |
sort(['abc', 'c', 'a', 'b']) | |
sort([5,1,2,7,3,0,1,2,5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment