mvlofthus / string-manipulation-practice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sorting & String Manipulation Practice

Wave 1 - Sort by Length

In this method you will take a string as a parameter. The method will return an array of words in the string, sorted by length. Solve the problem without using the ruby .sort method. When words are tied for length, maintain the order they appeared in the original string.

Wave 2 - Reverse Sentence

In this assignment, you'll design and implement one of the well-known string manipulation methods. Remember that a string is an array of characters. Algorithms that worked on restricted arrays will work on strings as well.

Optional Exercise

  • Design and implement a method to reverse the words in a sentence in place. The string of words to be reversed in passed in as the input parameter to the method.
    • Your algorithm should strive to optimize the space complexity as much as possible.
  • For example, if the method is called with input parameter of "Yoda   is    awesome", then the method should update the input string object to have the value "awesome    is   Yoda".
    • Note that the count of white spaces between words is preserved.
  • Share and explain the time and space complexities for your solution in the comments above the method.
    • If the complexity is shared in terms of n, your explanation must explain what n stands for.

Notes: * Do not use Ruby provided functionality for .reverse and .reverse!. * You may use .length method available in the String class.

About


Languages

Language:Ruby 90.3%Language:Dockerfile 9.4%Language:Shell 0.3%