From 18405e19e0ca553ada88ad8d9588eef8643bc56f Mon Sep 17 00:00:00 2001 From: blairvansant Date: Fri, 18 Aug 2017 09:11:41 -0500 Subject: [PATCH 1/3] pirateSpeak passes tests --- .../CodingChallenge.FamilyTree.Tests.csproj | 3 +++ .../CodingChallenge.PirateSpeak.Tests.csproj | 3 +++ CodingChallenge.PirateSpeak/Solution.cs | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CodingChallenge.FamilyTree.Tests/CodingChallenge.FamilyTree.Tests.csproj b/CodingChallenge.FamilyTree.Tests/CodingChallenge.FamilyTree.Tests.csproj index 07b4591..8e478dc 100644 --- a/CodingChallenge.FamilyTree.Tests/CodingChallenge.FamilyTree.Tests.csproj +++ b/CodingChallenge.FamilyTree.Tests/CodingChallenge.FamilyTree.Tests.csproj @@ -71,6 +71,9 @@ CodingChallenge.FamilyTree + + + diff --git a/CodingChallenge.PirateSpeak.Tests/CodingChallenge.PirateSpeak.Tests.csproj b/CodingChallenge.PirateSpeak.Tests/CodingChallenge.PirateSpeak.Tests.csproj index 9dc0f8e..e4a05e1 100644 --- a/CodingChallenge.PirateSpeak.Tests/CodingChallenge.PirateSpeak.Tests.csproj +++ b/CodingChallenge.PirateSpeak.Tests/CodingChallenge.PirateSpeak.Tests.csproj @@ -78,6 +78,9 @@ CodingChallenge.PirateSpeak + + + diff --git a/CodingChallenge.PirateSpeak/Solution.cs b/CodingChallenge.PirateSpeak/Solution.cs index 2c77075..06422e2 100644 --- a/CodingChallenge.PirateSpeak/Solution.cs +++ b/CodingChallenge.PirateSpeak/Solution.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; namespace CodingChallenge.PirateSpeak @@ -7,7 +8,20 @@ public class Solution { public string[] GetPossibleWords(string jumble, string[] dictionary) { - throw new NotImplementedException(); + List PossibleWords = new List(); + + String UnJumbledWord = String.Concat(jumble.OrderBy(i => i)); // arrange jumble words in alpha. order + + foreach (var word in dictionary) + { + string dictionaryWord = String.Concat(word.OrderBy(i => i)); // arrange dic. word in alpha. order + + if (dictionaryWord == UnJumbledWord) // if the two are = + { + PossibleWords.Add(word); // add word to the list + } + } + return PossibleWords.ToArray(); // return list to array } } -} \ No newline at end of file +} From 4b1a84c00928b6a1796c0706fe6dbf150477b5ed Mon Sep 17 00:00:00 2001 From: blairvansant Date: Fri, 18 Aug 2017 09:29:15 -0500 Subject: [PATCH 2/3] familyTree passes tests --- CodingChallenge.FamilyTree/Solution.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CodingChallenge.FamilyTree/Solution.cs b/CodingChallenge.FamilyTree/Solution.cs index 512487c..07a3cea 100644 --- a/CodingChallenge.FamilyTree/Solution.cs +++ b/CodingChallenge.FamilyTree/Solution.cs @@ -1,12 +1,24 @@ using System; +using System.Linq; namespace CodingChallenge.FamilyTree { public class Solution { public string GetBirthMonth(Person person, string descendantName) + { + var descendant = findDescendant(person, descendantName); + + return descendant?.Birthday.ToString("MMMM") ?? string.Empty; + } + + private Person findDescendant(Person person, string descendantName) { - throw new NotImplementedException(); + return person.Name == descendantName ? person : person.Descendants.Select(i => findDescendant(i, descendantName)).FirstOrDefault(result => result != null); } } -} \ No newline at end of file +} + + + + From 659653053f8d6795bc78233200f2fbad5c4cd8cf Mon Sep 17 00:00:00 2001 From: blairvansant Date: Fri, 18 Aug 2017 09:33:34 -0500 Subject: [PATCH 3/3] familyTree comments --- CodingChallenge.FamilyTree/Solution.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CodingChallenge.FamilyTree/Solution.cs b/CodingChallenge.FamilyTree/Solution.cs index 07a3cea..d02aabe 100644 --- a/CodingChallenge.FamilyTree/Solution.cs +++ b/CodingChallenge.FamilyTree/Solution.cs @@ -7,14 +7,14 @@ public class Solution { public string GetBirthMonth(Person person, string descendantName) { - var descendant = findDescendant(person, descendantName); + var descendant = findDescendant(person, descendantName); // search tree for descendant - return descendant?.Birthday.ToString("MMMM") ?? string.Empty; + return descendant?.Birthday.ToString("MMMM") ?? string.Empty; // return descendant } - private Person findDescendant(Person person, string descendantName) + private Person findDescendant(Person person, string descendantName) // search descendantName { - return person.Name == descendantName ? person : person.Descendants.Select(i => findDescendant(i, descendantName)).FirstOrDefault(result => result != null); + return person.Name == descendantName ? person : person.Descendants.Select(i => findDescendant(i, descendantName)).FirstOrDefault(result => result != null); // return descendant or null if not found } } }