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
25 changes: 20 additions & 5 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
public string getValue(string key)
{


return string.Empty;
var dict = createPerson();

return dict.GetValueOrDefault(key);

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.


}
Expand All @@ -64,7 +65,9 @@
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
return false;
var keyExists = dictionary.TryGetValue(isitthere, out var key);

return keyExists;

}

Expand All @@ -78,7 +81,12 @@
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
{
return 0;
var exists = dictionary.TryGetValue(isitthere, out var value);

if (exists)
return value;

return -1;

}

Expand All @@ -105,7 +113,14 @@
map.Add(96, "nice");
// Write your code below this comment...


foreach (var key in numbers)
{
var value = map.GetValueOrDefault(key);

if (value == null) continue;

results.Add(value);
}

// // ...and above this comment
return results;
Expand Down
12 changes: 8 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 @@
_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 @@ -36,7 +36,9 @@
// 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.Count());
}

return result;
}
Expand All @@ -52,7 +54,7 @@
}
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 +69,9 @@

public string FurthestFromTheSun()
{
return string.Empty;
var dict = OrderedPlanetsByDescending();
var furthest = dict.Keys.FirstOrDefault();
return furthest;

Check warning on line 74 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 74 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 74 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 74 in csharp-fundamentals-maps.Main/Extension.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}
public string ClosestToTheSun()
{
Expand Down
Loading