Sha256: c7b0e3b171dc630b977fc423c6e5fc936ec7defc05cc834301f387824250d1b3
Contents?: true
Size: 1.21 KB
Versions: 258
Compression:
Stored size: 1.21 KB
Contents
using System.Linq; using System.Text.RegularExpressions; public class PigLatin { public static string Translate(string word) { return string.Join(" ", word.Split(' ').Select(x => (TranslateWord(x)))); } private static string TranslateWord(string word) { if (WordStartsWithVowelLike(word)) return word + "ay"; if (WordStartsWithPrefixes(word, "thr", "sch")) return word.Substring(3) + word.Substring(0, 3) + "ay"; if (WordStartsWithPrefixes(word, "ch", "qu", "th")) return word.Substring(2) + word.Substring(0, 2) + "ay"; if (WordStartsWithConsonantAndQu(word)) return word.Substring(3) + word[0] + "quay"; return word.Substring(1) + word[0] + "ay"; } private static bool WordStartsWithVowelLike(string word) { return Regex.IsMatch("[aeiou]", word[0].ToString()) || word.StartsWith("yt") || word.StartsWith("xr"); } private static bool WordStartsWithPrefixes(string word, params string[] prefixes) { return prefixes.Any(word.StartsWith); } private static bool WordStartsWithConsonantAndQu(string word) { return word.Substring(1).StartsWith("qu"); } }
Version data entries
258 entries across 258 versions & 1 rubygems