Ruby Basic Exercises: Create a new string from a given string with the last character added at the front and back of the given string
Ruby Basic: Exercise-24 with Solution
Write a Ruby program to create a new string from a given string with the last character added at the front and back of the given string. The lenght of the given string must be 1 or more.
def temp(str) len = str.length() - 1; return (str.split('')[len] + str + str.split('')[len]); end print temp("abc"),"\n" print temp("abcd"),"\n" print temp("java")
cabcc dabcdd ajavaa
Ruby Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework