Skip to content

Conversation

@OhCloud
Copy link

@OhCloud OhCloud commented Nov 8, 2019

Sorting & Reverse Sentence

Question Answer
Describe how Bubble Sort works Bubble sort goes through and swaps the elements if theyre in the wrong order (to the right), and does it for the entirety of array, could take a while
Describe how Selection Sort works Good when memory is $$$, goes through to find the smallest one, puts it in order
Describe how Insertion sort works this works by comparing key elements to the previous one, if its bigger than key, move to the right.
Which Sorting Algorithm has the best time complexity? if done right, selection @ 0(n)
 

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working and it's clear from the tests it's not working. You do have reversing a string done, but little else is in place. I'm glad you got what you finished in, but take a look at my comments and let me know if they give you an idea where you could have proceeded from there.

initial += 1
last -= 1

return sentence

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return should be outside the while loop

Comment on lines +26 to +31
(min..max).each do |length|
sky_arr.each do |word|
if word.length == length
final_arr << word
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it works, but it's a little inefficient. Instead you could just do a bubblesort using the string lengths.

# shovel into my_new_array
# in a perfect world, would return in order we want

def reverse(sentence)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method reverses a string, it doesn't reverse the words in a sentence. You're on the right track.

Consider:

  1. Reverse the string
  2. Loop through reversing each word in the sentence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants