Given
30.02 -88.87 10.58 -99.22 107.33
to sort without the sort
method. I have spent a few hours on this without any success.
def simple_sort(list) # I have to start with this method
list = list.split(' ') # I understand i need to .split to get arrays
Because they're floats I need a way to make them floats with to_f
method .each(&:to_f)
I saw this before but I'm not sure I understand the ":
". I thought colon made objects symbols so anyone please explain (&:to_f)
to me?
sorted_list = [] #thought of creating an empty array to store the new list
This is the part that gets tricky! Where do I go from here?
I want to go through each item in the array, find the smallest number and add it to the sorted_list
def sort_list(list)
list = list.split(' ').map(&:to_f)
sort = []
while sort.length < list.length
sort << list.min
list.delete(list.min)
end
sort = sort.join(' ')
return sort
end
instead of using the <=>, what would make this code work?