From 9bc9a9aa218bd9665c85985a3cc090e747235ceb Mon Sep 17 00:00:00 2001 From: hellomarisamorris Date: Mon, 9 Oct 2017 19:01:09 -0700 Subject: [PATCH] methods complete --- .DS_Store | Bin 0 -> 6148 bytes string_manipulation.rb | 101 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 l + b += 1 + end + j = b - 1 + while i < j + temp = my_sentence[i] + my_sentence[i] = my_sentence[j] + my_sentence[j] = temp + i += 1 + j -= 1 + end + b += 1 + end + return my_sentence end + # A method to check if the input string is a palindrome. # Return true if the string is a palindrome. Return false otherwise. def palindrome_check(my_phrase) - puts "NOT IMPLEMENTED" + # puts "NOT IMPLEMENTED" + + index = 0 + length = my_phrase.length - 1 + + while index < length + if my_phrase[index] != my_phrase[length] + return false + end + index += 1 + length -= 1 + end return true end + +# ---------------------------------------------------------- + # A method that updates the string by replacing consecutive repeating characters # with a number representing the frequency. The replacement is done only if the # string length will get reduced by the process. def encode_repeating(my_string) puts "NOT IMPLEMENTED" + + end -### ---- END OF METHODS +## ---- END OF METHODS puts "Test 1: reverse a string" my_string = "Lovelace" puts "Original string: #{my_string}" @@ -39,6 +122,7 @@ def encode_repeating(my_string) puts "BUG! The reversed string should be '#{reversed_string}' and not '#{my_string}'" end + puts "Test 2: reversed words" my_words = "I can be an engineer" puts "Original: #{my_words}" @@ -50,6 +134,7 @@ def encode_repeating(my_string) puts "BUG! The reversed words should be '#{reversed_words}' and not '#{my_words}'" end + puts "Test 3: reversed sentence" sentence = "Yoda is awesome" puts "Original: #{sentence}" @@ -61,6 +146,7 @@ def encode_repeating(my_string) puts "BUG! The reversed sentence should be '#{reversed_sentence}' and not '#{sentence}'" end + puts "Test 4: Palindrome check" phrase = "madam" puts "BUG: madam is a palindrome and should return true" if palindrome_check(phrase) != true @@ -71,7 +157,8 @@ def encode_repeating(my_string) # puts "BUG: 'nurses run' is a palindrome and should return true" if palindrome_check(phrase) != true puts "Palindrome test complete." -# Optional Question #5 + +# #Optional Question #5 # puts "Test 5: Encode test" # test1 = "aaabbbbbcccc" # encode_repeating(test1)