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

public string getValue(string key)
{


return string.Empty;


var person = createPerson();
if (person.ContainsKey(key))
{
return person[key];
}
return null;

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

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

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

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

}

Expand All @@ -76,9 +77,16 @@
The method must use the string provided to return the integer contained in the provided HashMap,
or -1 if the string provided is not a key in the HashMap
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
public int getValueOrDefault(Dictionary<string, int> dictionary, string isitthere)
{
return 0;
if (dictionary.ContainsKey(isitthere))
{
return dictionary[isitthere];
}
else
{
return -1;
}

}

Expand All @@ -94,6 +102,7 @@
public List<string> buildSecretPhrase(int[] numbers)
{
List<string> results = new List<string>();
string value;

// Do not modify the map
Dictionary<int, string> map = new Dictionary<int, string>();
Expand All @@ -103,12 +112,17 @@
map.Add(6712, "bass");
map.Add(7, "muse");
map.Add(96, "nice");
// Write your code below this comment...


foreach (var number in numbers)
{
if (map.ContainsKey(number))
{
value = map[number];
results.Add(value);
}

// // ...and above this comment
return results;
}
return results;
}
}
}
19 changes: 14 additions & 5 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 @@ -31,13 +31,19 @@ public Dictionary<string,int> LettersInName()
{

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

foreach (KeyValuePair<string, float> kvp in _planets)
{
currentKey = kvp.Key;
int nameLength = currentKey.Length;
result.Add(currentKey, nameLength);
}

//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.



return result;
}

Expand All @@ -52,7 +58,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,8 +73,11 @@ public Dictionary<string, float> OrderedPlanetsByDescending()

public string FurthestFromTheSun()
{
return string.Empty;
KeyValuePair<string, float> result = OrderedPlanets().Last();

return result.Key;
}

public string ClosestToTheSun()
{
KeyValuePair<string, float> result = OrderedPlanets().First();
Expand Down
Loading