From e077d0aa20fa351053db7693b64f0130e5a41280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Jakob=20H=C3=A5land?= Date: Wed, 13 Aug 2025 08:41:22 +0200 Subject: [PATCH 1/2] Adds functionality to pass core tests --- csharp-fundamentals-maps.Main/Core.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/csharp-fundamentals-maps.Main/Core.cs b/csharp-fundamentals-maps.Main/Core.cs index 8f4d84a..6163c04 100644 --- a/csharp-fundamentals-maps.Main/Core.cs +++ b/csharp-fundamentals-maps.Main/Core.cs @@ -48,11 +48,8 @@ in the createPerson method public string getValue(string key) { - - - return string.Empty; - - + Dictionary map = createPerson(); + return map[key]; } //TODO: 2. Modify below method named hasKey that accepts two parameters: @@ -64,7 +61,7 @@ in the provided dictionary */ public bool hasKey(Dictionary dictionary, string isitthere) { - return false; + return dictionary.ContainsKey(isitthere); } @@ -78,7 +75,7 @@ public bool hasKey(Dictionary dictionary, string isitthere) */ public int getValueOrDefault(Dictionary dictionary, string isitthere) { - return 0; + return dictionary.ContainsKey(isitthere) ? dictionary[isitthere] : -1; } @@ -104,7 +101,13 @@ public List buildSecretPhrase(int[] numbers) map.Add(7, "muse"); map.Add(96, "nice"); // Write your code below this comment... - + foreach (int number in numbers) + { + if (map.ContainsKey(number)) + { + results.Add(map[number]); + } + } // // ...and above this comment From f21065960661d939e5104dc5053144113db37be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Jakob=20H=C3=A5land?= Date: Wed, 13 Aug 2025 08:51:04 +0200 Subject: [PATCH 2/2] Adds fuctionality to pass extension tests --- csharp-fundamentals-maps.Main/Extension.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/csharp-fundamentals-maps.Main/Extension.cs b/csharp-fundamentals-maps.Main/Extension.cs index 2deb96d..988c43f 100644 --- a/csharp-fundamentals-maps.Main/Extension.cs +++ b/csharp-fundamentals-maps.Main/Extension.cs @@ -16,7 +16,7 @@ public Extension() _planets = new Dictionary(); _planets.Add("Jupiter", 5.2f); _planets.Add("Uranus", 19.2f); - _planets.Add("Pluto", 39f); + //_planets.Add("Pluto", 39f); _planets.Add("Mercury", 0.39f); _planets.Add("Saturn", 9.54f); _planets.Add("Earth", 1f); @@ -36,7 +36,10 @@ public Dictionary LettersInName() // the planet name and the number of letters in its name // iterate the _planets using a foreach object to load the result dictionary. - + foreach (KeyValuePair keyValuePair in _planets) + { + result.Add(keyValuePair.Key, keyValuePair.Key.ToString().Length); + } return result; } @@ -52,7 +55,7 @@ public Dictionary OrderedPlanets() } public Dictionary OrderedPlanetsByDescending() { - return _planets.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value); + return _planets.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); } //TODO: modify the OrderedPlanetsByDescending so it is not dictionary is not doing an OrderBy but OrderByDescending @@ -67,7 +70,8 @@ public Dictionary OrderedPlanetsByDescending() public string FurthestFromTheSun() { - return string.Empty; + KeyValuePair result = OrderedPlanetsByDescending().First(); + return result.Key; } public string ClosestToTheSun() {