From da655c88448e28b6e4740bd358a2abc9c61cbc44 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Sat, 21 Sep 2019 10:41:07 -0700 Subject: [PATCH 01/12] Implementing bubble sort method. Some tests are passing. --- lib/reverse_sentence.rb | 35 ++++++++++++++++ test/reverse_sentence_test.rb | 40 ++++++++----------- ...rt_by_length.rb => sort_by_length_test.rb} | 4 +- 3 files changed, 54 insertions(+), 25 deletions(-) rename test/{sort_by_length.rb => sort_by_length_test.rb} (99%) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 3fe7cac..bb66655 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -2,5 +2,40 @@ # Time complexity: ? # Space complexity: ? def reverse_sentence(my_sentence) + # turn my sentence into an array of strings + array = my_sentence.split + length = array.length + + i = 0 + while i < length-1 # outer loop + j = 0 + while j < length-i-1 # inner loop + if array[j] > array[j+1] # swap + temp = array[j] + array[j] = array[j+1] + array[j+1] = temp + end + j += 1 + end + i += 1 + end + return array raise NotImplementedError end + + +# def bubble_sort(array, length) +# i = 0 +# while i < length-1 # outer loop +# j = 0 +# while j < length-i-1 # inner loop +# if array[j] > array[j+1] # swap +# temp = array[j] +# array[j] = array[j+1] +# array[j+1] = temp +# end +# j += 1 +# end +# i += 1 +# end +# end diff --git a/test/reverse_sentence_test.rb b/test/reverse_sentence_test.rb index 346069b..49be995 100644 --- a/test/reverse_sentence_test.rb +++ b/test/reverse_sentence_test.rb @@ -4,70 +4,64 @@ describe "basic tests" do it "reverse a sentence with two words" do test_string = "hello, world" - reverse_sentence(test_string) - test_string.must_equal "world hello," end - + it "reverse a sentence with three words" do test_string = "Yoda is awesome!" - reverse_sentence(test_string) - test_string.must_equal "awesome! is Yoda" end end - + # check for edge cases describe "edge cases" do # if it's a string parameter, check for empty it "reverse an empty sentence" do test_string = "" - reverse_sentence(test_string) - test_string.must_be_empty end - + # if the parameter is an object, check for nil it "nil object passed to sentence reverse" do test_string = nil - + reverse_sentence(test_string) - + test_string.must_be_nil end - + it "reverse a sentence with one word" do test_string = "world" - + reverse_sentence(test_string) - + test_string.must_equal "world" end - + it "reverse a sentence with multiple words" do test_string = "I'm a better engineer today than I was yesterday." - + reverse_sentence(test_string) - + test_string.must_equal "yesterday. was I than today engineer better a I'm" end - + it "reverse a sentence with multiple spaces between words" do test_string = "How do you like them apples?" - + reverse_sentence(test_string) - + test_string.must_equal "apples? them like you do How" end - + it "reverse a sentence with preceeding and trailing white spaces" do test_string = " I can do this! " - + reverse_sentence(test_string) - + test_string.must_equal " this! do can I " end end diff --git a/test/sort_by_length.rb b/test/sort_by_length_test.rb similarity index 99% rename from test/sort_by_length.rb rename to test/sort_by_length_test.rb index c38d976..1eb292f 100644 --- a/test/sort_by_length.rb +++ b/test/sort_by_length_test.rb @@ -8,11 +8,11 @@ it "will return an array of words, by length" do expect(sort_by_length("I love Ada")).must_equal ["I", "Ada", "love"] end - + it "will return an array of words by length, words that are of equal length will appear in the order they appear" do expect(sort_by_length("words of equal length")).must_equal ["of", "words", "equal", "length"] end - + it "will return an array of words by length, words that are of equal length will appear in the order they appear" do expect(sort_by_length("I love great awesome words")).must_equal ["I", "love", "great", "words", "awesome"] end From 3d64699c47f7d1dd1f7485f08856d008b32a94f7 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 09:26:58 -0700 Subject: [PATCH 02/12] Kind of confused and starting over. --- lib/reverse_sentence.rb | 37 +++-------------------------------- test/reverse_sentence_test.rb | 31 ++++++++++++----------------- test/sort_by_length_test.rb | 34 ++++++++++++++++---------------- 3 files changed, 32 insertions(+), 70 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index bb66655..94b4ca5 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -2,40 +2,9 @@ # Time complexity: ? # Space complexity: ? def reverse_sentence(my_sentence) - # turn my sentence into an array of strings - array = my_sentence.split - length = array.length - - i = 0 - while i < length-1 # outer loop - j = 0 - while j < length-i-1 # inner loop - if array[j] > array[j+1] # swap - temp = array[j] - array[j] = array[j+1] - array[j+1] = temp - end - j += 1 - end - i += 1 + if my_sentence.nil? + return my_sentence end - return array + raise NotImplementedError end - - -# def bubble_sort(array, length) -# i = 0 -# while i < length-1 # outer loop -# j = 0 -# while j < length-i-1 # inner loop -# if array[j] > array[j+1] # swap -# temp = array[j] -# array[j] = array[j+1] -# array[j+1] = temp -# end -# j += 1 -# end -# i += 1 -# end -# end diff --git a/test/reverse_sentence_test.rb b/test/reverse_sentence_test.rb index 49be995..18370dc 100644 --- a/test/reverse_sentence_test.rb +++ b/test/reverse_sentence_test.rb @@ -35,34 +35,27 @@ it "reverse a sentence with one word" do test_string = "world" - reverse_sentence(test_string) - test_string.must_equal "world" end it "reverse a sentence with multiple words" do test_string = "I'm a better engineer today than I was yesterday." - reverse_sentence(test_string) - test_string.must_equal "yesterday. was I than today engineer better a I'm" end it "reverse a sentence with multiple spaces between words" do test_string = "How do you like them apples?" - - reverse_sentence(test_string) - - test_string.must_equal "apples? them like you do How" - end - - it "reverse a sentence with preceeding and trailing white spaces" do - test_string = " I can do this! " - - reverse_sentence(test_string) - - test_string.must_equal " this! do can I " - end - end -end + reverse_sentence(test_string) + test_string.must_equal "apples? them like you do How" + end + + it "reverse a sentence with preceeding and trailing white spaces" do + test_string = " I can do this! " + reverse_sentence(test_string) + test_string.must_equal " this! do can I " + end + end + end + \ No newline at end of file diff --git a/test/sort_by_length_test.rb b/test/sort_by_length_test.rb index 1eb292f..11a2941 100644 --- a/test/sort_by_length_test.rb +++ b/test/sort_by_length_test.rb @@ -1,19 +1,19 @@ require_relative "test_helper" -describe "sort_by_length" do - it "will return an empty array for an empty string" do - expect(sort_by_length("")).must_equal [] - end - - it "will return an array of words, by length" do - expect(sort_by_length("I love Ada")).must_equal ["I", "Ada", "love"] - end - - it "will return an array of words by length, words that are of equal length will appear in the order they appear" do - expect(sort_by_length("words of equal length")).must_equal ["of", "words", "equal", "length"] - end - - it "will return an array of words by length, words that are of equal length will appear in the order they appear" do - expect(sort_by_length("I love great awesome words")).must_equal ["I", "love", "great", "words", "awesome"] - end -end \ No newline at end of file +# describe "sort_by_length" do +# it "will return an empty array for an empty string" do +# expect(sort_by_length("")).must_equal [] +# end + +# it "will return an array of words, by length" do +# expect(sort_by_length("I love Ada")).must_equal ["I", "Ada", "love"] +# end + +# it "will return an array of words by length, words that are of equal length will appear in the order they appear" do +# expect(sort_by_length("words of equal length")).must_equal ["of", "words", "equal", "length"] +# end + +# it "will return an array of words by length, words that are of equal length will appear in the order they appear" do +# expect(sort_by_length("I love great awesome words")).must_equal ["I", "love", "great", "words", "awesome"] +# end +# end \ No newline at end of file From ecb9c885e39f4968691a80de239162504be916ee Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 09:37:23 -0700 Subject: [PATCH 03/12] It is not producing th desired result but I am learning something. --- lib/reverse_sentence.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 94b4ca5..8916762 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -6,5 +6,17 @@ def reverse_sentence(my_sentence) return my_sentence end + + i = 0 + j = (my_sentence.length - 1) + + until i == my_sentence.length + holding = my_sentence[j] + my_sentence[i] = holding + i += 1 + j -= 1 + end + + return my_sentence raise NotImplementedError end From d9c85e48c153c48ca89c16c1417b0e73e7522fb5 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 09:41:55 -0700 Subject: [PATCH 04/12] I've now reversed all characters and am thinking about how to swap each word in place. --- lib/reverse_sentence.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 8916762..d9db852 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -9,7 +9,9 @@ def reverse_sentence(my_sentence) i = 0 j = (my_sentence.length - 1) + punctuation = [',', '.', '!', ':', ';', '?'] + # reverses each character until i == my_sentence.length holding = my_sentence[j] my_sentence[i] = holding @@ -17,6 +19,11 @@ def reverse_sentence(my_sentence) j -= 1 end + # swap each character of each word back into space + my_sentence + until + end + return my_sentence raise NotImplementedError end From 2a08d1db84b6fb0e6e2efe02b5deacd629899eb1 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 10:09:30 -0700 Subject: [PATCH 05/12] sorty_by_length method tests are passing --- lib/reverse_sentence.rb | 42 +++++++++++++++++------------------ lib/sort_by_length.rb | 28 +++++++++++++++++++++++ test/reverse_sentence_test.rb | 2 +- test/sort_by_length_test.rb | 34 ++++++++++++++-------------- 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index d9db852..0a94a1d 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -2,28 +2,28 @@ # Time complexity: ? # Space complexity: ? def reverse_sentence(my_sentence) - if my_sentence.nil? - return my_sentence - end + # length = my_sentence.length + # i = 0 - i = 0 - j = (my_sentence.length - 1) - punctuation = [',', '.', '!', ':', ';', '?'] - - # reverses each character - until i == my_sentence.length - holding = my_sentence[j] - my_sentence[i] = holding - i += 1 - j -= 1 - end - - # swap each character of each word back into space - my_sentence - until - end - - return my_sentence + # # # If the inner loop runs with no swaps, exit + # swapped = true + # while i < length-1 && swapped # outer loop + # j = 0 + # Assume you won't have to make a swap + # # swapped = false + # # while j < length-i-1 # inner loop + # # if array[j] > array[j+1] # swap + # # temp = array[j] + # # array[j] = array[j+1] + # # array[j+1] = temp + # # # Since we just made a swap, set swapped to true + # # swapped = true + # # end + # j += 1 + # end + # i += 1 + # end + # end raise NotImplementedError end diff --git a/lib/sort_by_length.rb b/lib/sort_by_length.rb index a5713ad..1d4be05 100644 --- a/lib/sort_by_length.rb +++ b/lib/sort_by_length.rb @@ -3,5 +3,33 @@ # Time complexity: ? # Space complexity: ? def sort_by_length(my_sentence) + if my_sentence == "" + return [] + end + + array = my_sentence.split(' ') + # longest_string = array.first + length = array.length + + # If the inner loop runs with no swaps, exit + swapped = true + i = 0 + while i < length-1 && swapped # outer loop + j = 0 + # Assume you won't have to make a swap + swapped = false + while j < length-i-1 # inner loop + if array[j].length > array[j+1].length # swap + temp = array[j] + array[j] = array[j+1] + array[j+1] = temp + # Since we just made a swap, set swapped to true + swapped = true + end + j += 1 + end + i += 1 + end + return array raise NotImplementedError, "Method not implemented" end diff --git a/test/reverse_sentence_test.rb b/test/reverse_sentence_test.rb index 18370dc..5ed14ef 100644 --- a/test/reverse_sentence_test.rb +++ b/test/reverse_sentence_test.rb @@ -27,7 +27,7 @@ # if the parameter is an object, check for nil it "nil object passed to sentence reverse" do test_string = nil - + reverse_sentence(test_string) test_string.must_be_nil diff --git a/test/sort_by_length_test.rb b/test/sort_by_length_test.rb index 11a2941..1eb292f 100644 --- a/test/sort_by_length_test.rb +++ b/test/sort_by_length_test.rb @@ -1,19 +1,19 @@ require_relative "test_helper" -# describe "sort_by_length" do -# it "will return an empty array for an empty string" do -# expect(sort_by_length("")).must_equal [] -# end - -# it "will return an array of words, by length" do -# expect(sort_by_length("I love Ada")).must_equal ["I", "Ada", "love"] -# end - -# it "will return an array of words by length, words that are of equal length will appear in the order they appear" do -# expect(sort_by_length("words of equal length")).must_equal ["of", "words", "equal", "length"] -# end - -# it "will return an array of words by length, words that are of equal length will appear in the order they appear" do -# expect(sort_by_length("I love great awesome words")).must_equal ["I", "love", "great", "words", "awesome"] -# end -# end \ No newline at end of file +describe "sort_by_length" do + it "will return an empty array for an empty string" do + expect(sort_by_length("")).must_equal [] + end + + it "will return an array of words, by length" do + expect(sort_by_length("I love Ada")).must_equal ["I", "Ada", "love"] + end + + it "will return an array of words by length, words that are of equal length will appear in the order they appear" do + expect(sort_by_length("words of equal length")).must_equal ["of", "words", "equal", "length"] + end + + it "will return an array of words by length, words that are of equal length will appear in the order they appear" do + expect(sort_by_length("I love great awesome words")).must_equal ["I", "love", "great", "words", "awesome"] + end +end \ No newline at end of file From 8799444c89399b20bf7c5cd9ac90f78896664ec1 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 11:33:37 -0700 Subject: [PATCH 06/12] Still no solution for reverse sentence but saving work. --- lib/reverse_sentence.rb | 51 ++++++++++++++++++++++++----------------- lib/sort_by_length.rb | 1 + 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 0a94a1d..d6ed0d1 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -1,29 +1,38 @@ # A method to reverse the words in a sentence, in place. # Time complexity: ? # Space complexity: ? +require 'pry' def reverse_sentence(my_sentence) - # length = my_sentence.length + if my_sentence == "" + return "" + elsif my_sentence == nil + return nil + end - # i = 0 + array = my_sentence.split(' ') + length = array.length + i = 0 + # If the inner loop runs with no swaps, exit + swapped = true + while i < length-1 && swapped # outer loop + j = 0 + # Assume you won't have to make a swap + swapped = false + while j < length-i-1 # inner loop + if array[j] > array[j+1] # swap + temp = array[j] + array[j] = array[j+1] + array[j+1] = temp + # Since we just made a swap, set swapped to true + swapped = true + end + j += 1 + end + i += 1 + end + + + return array - # # # If the inner loop runs with no swaps, exit - # swapped = true - # while i < length-1 && swapped # outer loop - # j = 0 - # Assume you won't have to make a swap - # # swapped = false - # # while j < length-i-1 # inner loop - # # if array[j] > array[j+1] # swap - # # temp = array[j] - # # array[j] = array[j+1] - # # array[j+1] = temp - # # # Since we just made a swap, set swapped to true - # # swapped = true - # # end - # j += 1 - # end - # i += 1 - # end - # end raise NotImplementedError end diff --git a/lib/sort_by_length.rb b/lib/sort_by_length.rb index 1d4be05..aea48ec 100644 --- a/lib/sort_by_length.rb +++ b/lib/sort_by_length.rb @@ -30,6 +30,7 @@ def sort_by_length(my_sentence) end i += 1 end + return array raise NotImplementedError, "Method not implemented" end From 4c16074fda89add82253d6a43b7f5ff310a5c424 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 14:47:52 -0700 Subject: [PATCH 07/12] I think that the reverse sentence method is closer but still not there --- lib/reverse_sentence.rb | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index d6ed0d1..e848097 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -9,30 +9,22 @@ def reverse_sentence(my_sentence) return nil end - array = my_sentence.split(' ') - length = array.length - i = 0 - # If the inner loop runs with no swaps, exit - swapped = true - while i < length-1 && swapped # outer loop - j = 0 - # Assume you won't have to make a swap - swapped = false - while j < length-i-1 # inner loop - if array[j] > array[j+1] # swap - temp = array[j] - array[j] = array[j+1] - array[j+1] = temp - # Since we just made a swap, set swapped to true - swapped = true - end - j += 1 - end - i += 1 + my_sentence = my_sentence.split(' ') + length = my_sentence.length + second_array = [] + + length.times do |i| + second_array[i] = my_sentence[length-1 - i] end + length.times do |i| + my_sentence[i] = second_array[i] + end - return array + # my_sentence = array.join(" ") + my_sentence = my_sentence.join(" ") + return my_sentence - raise NotImplementedError + raise NotImplementedError, "Method not implemented" end + From afafdd15a5d49d0a0d2c454a2caec599f3afa120 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Mon, 23 Sep 2019 21:58:07 -0700 Subject: [PATCH 08/12] Saving some work on reverse_sentence.rb --- lib/reverse_sentence.rb | 58 ++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index e848097..3028f06 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -2,6 +2,7 @@ # Time complexity: ? # Space complexity: ? require 'pry' + def reverse_sentence(my_sentence) if my_sentence == "" return "" @@ -9,22 +10,49 @@ def reverse_sentence(my_sentence) return nil end - my_sentence = my_sentence.split(' ') length = my_sentence.length - second_array = [] - - length.times do |i| - second_array[i] = my_sentence[length-1 - i] - end + reversaroo(my_sentence, length) + # first fully reverse the strings - length.times do |i| - my_sentence[i] = second_array[i] + # then know which spots are words and reverse those in place + split_sentence = my_sentence.split(' ') + word_in_order_array = [] + split_sentence.each_with_index do |word, i| + length = word.length + temp = reversaroo(word, length) + word_in_order_array.push(temp) end - # my_sentence = array.join(" ") - my_sentence = my_sentence.join(" ") - return my_sentence - - raise NotImplementedError, "Method not implemented" -end - + # word_in_order_array has each word flipped back in place, now to replace the characters of my_sentence + x = 0 + z = 0 + my_sentence.each_char do |char| + if char == word_in_order_array[x][z] + my_sentence.insert(x, word_in_order_array[x]) + x += 1 + else + + end + # my_sentence is what i need to work with + # third_array.each do |word| + # length = word.length + # first_char = word[0] + # last_char = word[length-1] + # raise NotImplementedError + # end + + + def reversaroo(string, length) + j = (length - 1) + i = 0 + while i < j + temp = string[i] + string[i] = string[j] + string[j] = temp + j -= 1 + i += 1 + end + return string + end + + reverse_sentence("hi natalie") \ No newline at end of file From 06aeb4bd7df36745ba20805cacb69b92093aecbc Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Tue, 24 Sep 2019 16:59:33 -0700 Subject: [PATCH 09/12] I literally cannot believe that this is working. --- lib/reverse_sentence.rb | 57 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 3028f06..0285bb1 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -23,36 +23,35 @@ def reverse_sentence(my_sentence) word_in_order_array.push(temp) end - # word_in_order_array has each word flipped back in place, now to replace the characters of my_sentence x = 0 - z = 0 - my_sentence.each_char do |char| - if char == word_in_order_array[x][z] - my_sentence.insert(x, word_in_order_array[x]) - x += 1 - else - - end - # my_sentence is what i need to work with - # third_array.each do |word| - # length = word.length - # first_char = word[0] - # last_char = word[length-1] - # raise NotImplementedError - # end - + word_in_order_array.each do |word| - def reversaroo(string, length) - j = (length - 1) - i = 0 - while i < j - temp = string[i] - string[i] = string[j] - string[j] = temp - j -= 1 - i += 1 + word.each_char do |char| + until my_sentence[x] != " " + x += 1 end - return string + my_sentence[x] = char + x += 1 + end - - reverse_sentence("hi natalie") \ No newline at end of file + end + # search for any character or whitespace followed immediately by a character + return my_sentence +end + + + + +def reversaroo(string, length) + j = (length - 1) + i = 0 + while i < j + temp = string[i] + string[i] = string[j] + string[j] = temp + j -= 1 + i += 1 + end + return string +end + From 928057915c27d00ec92b8650ab1dc0e4bc111b53 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Tue, 24 Sep 2019 17:01:44 -0700 Subject: [PATCH 10/12] Cleaning up --- lib/reverse_sentence.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index 0285bb1..e402d5b 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -25,23 +25,20 @@ def reverse_sentence(my_sentence) x = 0 word_in_order_array.each do |word| - word.each_char do |char| until my_sentence[x] != " " x += 1 end my_sentence[x] = char x += 1 - end end # search for any character or whitespace followed immediately by a character return my_sentence + raise NotImplementedError end - - def reversaroo(string, length) j = (length - 1) i = 0 From 869761592374352d27b9c02f4df165882b4d16e7 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Tue, 24 Sep 2019 17:08:00 -0700 Subject: [PATCH 11/12] answering a few more comprehension questions for reverse_sentence.rb --- lib/reverse_sentence.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/reverse_sentence.rb b/lib/reverse_sentence.rb index e402d5b..f1b5e0f 100644 --- a/lib/reverse_sentence.rb +++ b/lib/reverse_sentence.rb @@ -1,6 +1,6 @@ # A method to reverse the words in a sentence, in place. -# Time complexity: ? -# Space complexity: ? +# Time complexity: O(n^3) +# Space complexity: O(n) I believe since there is a second array created in memory to store/reverse each word require 'pry' def reverse_sentence(my_sentence) @@ -14,7 +14,7 @@ def reverse_sentence(my_sentence) reversaroo(my_sentence, length) # first fully reverse the strings - # then know which spots are words and reverse those in place + # take each 'word' and split into an array. then reversaroo the each word and store in an array called word_in_order_array split_sentence = my_sentence.split(' ') word_in_order_array = [] split_sentence.each_with_index do |word, i| From 4c617d3626f24be93137cbaf476687f6b5211598 Mon Sep 17 00:00:00 2001 From: Natalie Tapias Date: Tue, 24 Sep 2019 17:14:16 -0700 Subject: [PATCH 12/12] Completed sort_by_length time & space complexity questions --- lib/sort_by_length.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sort_by_length.rb b/lib/sort_by_length.rb index aea48ec..bf7e2ef 100644 --- a/lib/sort_by_length.rb +++ b/lib/sort_by_length.rb @@ -1,7 +1,7 @@ # A method which will return an array of the words in the string # sorted by the length of the word. -# Time complexity: ? -# Space complexity: ? +# Time complexity: O(n^2) +# Space complexity: O(1) constat I believe def sort_by_length(my_sentence) if my_sentence == "" return []