Skip to content

Commit

Permalink
All tests complete
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMathiasson committed Aug 13, 2024
1 parent f7fedbd commit 80502dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
21 changes: 17 additions & 4 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ in the createPerson method

public string getValue(string key)
{

Dictionary<string, string> map = createPerson();


return string.Empty;
return map[key];


}
Expand All @@ -64,6 +65,10 @@ in the provided dictionary
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
if(dictionary.ContainsKey(isitthere))
{
return true;
}
return false;

}
Expand All @@ -78,7 +83,12 @@ public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
{
return 0;

if(dictionary.ContainsKey(isitthere))
{
return dictionary[isitthere];
}
return -1;

}

Expand All @@ -104,8 +114,11 @@ public List<string> buildSecretPhrase(int[] numbers)
map.Add(7, "muse");
map.Add(96, "nice");
// Write your code below this comment...
foreach (var num in numbers)
{
results.Add(map[num]);
}



// // ...and above this comment
return results;
Expand Down
13 changes: 9 additions & 4 deletions csharp-fundamentals-maps.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Extension()
_planets = new Dictionary<string, float>();
_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);
Expand All @@ -25,6 +25,7 @@ public Extension()
_planets.Add("Neptune", 30.06f);
}
//TODO Pluto is unfortunately no longer a planet so please comment out the add line!
// o7 yes, sir


public Dictionary<string,int> LettersInName()
Expand All @@ -35,8 +36,12 @@ public Dictionary<string,int> LettersInName()
//TODO Complete this method to return an Dictionary of <string,int> which contains
// the planet name and the number of letters in its name
// iterate the _planets using a foreach object to load the result dictionary.
foreach (var planet in _planets)
{
result.Add(planet.Key, planet.Key.Length);
}




return result;
}
Expand All @@ -52,7 +57,7 @@ public Dictionary<string,float> OrderedPlanets()
}
public Dictionary<string, float> 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

Expand All @@ -67,7 +72,7 @@ public Dictionary<string, float> OrderedPlanetsByDescending()

public string FurthestFromTheSun()
{
return string.Empty;
return OrderedPlanets().Last().Key;
}
public string ClosestToTheSun()
{
Expand Down

0 comments on commit 80502dd

Please sign in to comment.