Quantcast
Channel: User user2023861 - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 35

Answer by user2023861 for String reversal, capitalize vowels, lowercase consonants

$
0
0

You can make use of char static methods to do a lot of the work for you. Also, there's no need to memorize the ASCII values of vowels. Just use the vowels themselves.

static string Problem(string arg){    if (arg == null)        return null;    char[] vowels = "aeiouAEIOU".ToCharArray();    StringBuilder result = new StringBuilder();    for (int i = arg.Length - 1; i >= 0; i--)    {        char ch = arg[i];        if (vowels.Contains(ch))            result.Append(char.ToUpper(ch));        else            result.Append(char.ToLower(ch));    }    return result.ToString();}

This solution relies on the assumption that we're working with English. It's a good idea in interviews to clarify the question so that you don't have to make assumptions. Since this was a test, you may not have had the opportunity to ask questions. In that case, simply state your assumptions in code comments.


Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>