Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CodingChallenge.PirateSpeak/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Solution().GetPossibleWords("boop", new [] {"oops","poo","boo","noop"}));
}
var result = new Solution().GetPossibleWords("boop", new[] { "oops", "poo", "boo", "noop" });

Console.WriteLine(string.Join(", ", result));
}
}
}
23 changes: 21 additions & 2 deletions CodingChallenge.PirateSpeak/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

namespace CodingChallenge.PirateSpeak
{
public class Solution
{
public string[] GetPossibleWords(string jumble, string[] dictionary)
{
throw new NotImplementedException();
var result = new List<string>();
var jumbleSorted = Sort(jumble);
foreach (var word in dictionary)
{
if (jumbleSorted.Equals(Sort(word)))
{
result.Add(word);
}
}
return result.ToArray();
}
}

private string Sort(string word)
{
char[] wordAsArray = word.ToCharArray();
Array.Sort(wordAsArray);
var wordSorted = string.Join(' ', wordAsArray);
return wordSorted;
}
}
}