The weekend is over so better content coming soon, but today I completed code challenges, which was cool.
The ones that I completed were relatively easy, but it still feels good to be able to find solutions to coding challenges as a "codenewbie"
Challenge 1 - Remove the vowels from a string
The challenge asked for me to create a function that takes a string as an argument and returns a new string with all vowels removed.
I wrote the following code:
def disemvowel(string)
string.gsub(/[aeiouAEIOU]/, '')
end
It worked perfectly and I was able to move on to the next challenge. However, as I go through challenges I realized that I do not only want to find the "answer" but I want to find multiple ways to solve the answer. So I also found another way to solve the problem using tr which "returns a copy of str with the characters in from_str replaced by the corresponding characters in to_str." :
def disemvowel(string)
string.tr('aeiouAEIOU', "")
end
Both ways will work but as a software engineer it is important to constantly find different or new solutions for all problems that are presented to you. The same code can be written in many ways and in many different languages, it is important to learn and know different solutions for various issues that may arise.
Excited for future code challenges and the solutions I develop.
Song of the day:
Top comments (0)