Created
June 19, 2018 22:11
-
-
Save fredyfx/0eae64f3ad04daccc4b97767b498fe23 to your computer and use it in GitHub Desktop.
Welcome. In this kata you are required to, given a string, replace every letter with its position in the alphabet. If anything in the text isn't a letter, ignore it and don't return it. a being 1, b being 2, etc. As an example: string to input: ""The sunset sets at twelve o' clock.". Should return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Text; | |
public static class Kata | |
{ | |
public static string AlphabetPosition(string text) | |
{ | |
//First define the groups: | |
var ValidInput = new char[]{ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; | |
//Positions in array + 1 = number | |
StringBuilder sb = new StringBuilder(); | |
foreach (var item in text.ToLower().ToCharArray()){ | |
if(ValidInput.Contains(item)){ | |
sb.Append(Array.IndexOf(ValidInput, item) + 1); | |
sb.Append(" "); | |
} | |
} | |
return sb.ToString().TrimEnd();; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
public static class Kata | |
{ | |
public static string AlphabetPosition(string text) | |
{ | |
return string.Join(" ", text.ToLower().Where(char.IsLetter).Select(x => x - 'a'+1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment