Day 12/100 — Letter Changes Algorithm on Coderbyte

Tim Parsons
Sep 1, 2018 · 2 min read

I was told by a friend to try and get used to doing algorithms under pressure and mentioned that in a previous career he used to have to tackle issues in his industry under time constraints — maybe I should give it a try. Do as much as I can in 15 minutes. If I don’t figure it out, study the answers and figure

I started it a couple of days ago and found it helpful in helping me learn a little more but Medium seemed like a better place to right it down.

So here is the problem:

Using the JavaScript language, have the function LetterChanges(str) take the str parameter being passed and modify it using the following algorithm. Replace every letter in the string with the letter following it in the alphabet (ie. c becomes d, z becomes a). Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string.

function LetterChanges(str) {// code goes here  
return str;

}

// keep this function call here
LetterChanges(readline());

Shouldn’t be too difficult I thought. But 15 minutes goes pretty quickly. First I thought about splitting the string with .split(‘’). Then map through the array to add 1 to the .charCodeAt method and then get the final result. From there, use a regex expression to find all the vowels and use the .toUpperCase method to capitalize them.

Where I got to after 15 minutes

The code above is where I got to. The problem is, it didn’t give me the answer I needed. This is what I got.

After looking at the answers, it looks like I was still a way off. Along the right lines in some ways but still a way off. Here is my favorite answer by leot75.

My favorite answer

Looks like I need to keep learning and working harder. This is concise and a way of doing an algorithm I’ve never seen before. I like it.

If you have any comments, suggestions or ways to think more clearly, please leave a message in the comments below.

Follow me on twitter at @timmparsons.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade