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
18 changes: 7 additions & 11 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@

public string getValue(string key)
{


return string.Empty;


return createPerson()[key];
}

//TODO: 2. Modify below method named hasKey that accepts two parameters:
Expand All @@ -64,7 +60,7 @@
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
return false;
return dictionary.ContainsKey(isitthere);

}

Expand All @@ -78,8 +74,7 @@
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
{
return 0;

return dictionary[isitthere];
}


Expand All @@ -104,9 +99,10 @@
map.Add(7, "muse");
map.Add(96, "nice");
// Write your code below this comment...



foreach (int number in numbers)
{
results.Add(map.GetValueOrDefault(number));

Check warning on line 104 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 104 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 104 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 104 in csharp-fundamentals-maps.Main/Core.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.
}
// // ...and above this comment
return results;
}
Expand Down
12 changes: 9 additions & 3 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 @@ -32,6 +32,11 @@ public Dictionary<string,int> LettersInName()

Dictionary<string, int> result = new Dictionary<string, int>();

foreach(var p in _planets)
{
result.Add(p.Key, p.Key.Count());
}

//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.
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,8 @@ public Dictionary<string, float> OrderedPlanetsByDescending()

public string FurthestFromTheSun()
{
return string.Empty;

return OrderedPlanetsByDescending().First().Key;
}
public string ClosestToTheSun()
{
Expand Down
6 changes: 6 additions & 0 deletions csharp-fundamentals-maps.Test/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public CoreTests()
[Test]
public void getValueTest()
{
Dictionary<string, string> map = new Dictionary<string, string>();

map.Add("firstName", "Nigel");
map.Add("lastName", "Sibbert");
map.Add("currentTown", "Bournemouth");

Assert.AreEqual("Nigel", this.exercise.getValue("firstName"));
Assert.AreEqual("Sibbert", this.exercise.getValue("lastName"));
Assert.AreEqual("Software Developer", this.exercise.getValue("occupation"));
Expand Down
Loading