Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silje Jacobsen #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
26 changes: 16 additions & 10 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ in the createPerson method

public string getValue(string key)
{


return string.Empty;


Dictionary<string, string> map = createPerson();
return map[key];
}

//TODO: 2. Modify below method named hasKey that accepts two parameters:
Expand All @@ -64,9 +61,12 @@ in the provided dictionary
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
if (dictionary.ContainsKey(isitthere)) {
return true;
}
return false;
}

}


//TODO: 3. Modify method named getValueOrDefault that accepts two parameters:
Expand All @@ -78,7 +78,10 @@ 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 @@ -105,10 +108,13 @@ public List<string> buildSecretPhrase(int[] numbers)
map.Add(96, "nice");
// Write your code below this comment...


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

// // ...and above this comment
return results;
}
}
}
}
15 changes: 11 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 @@ -36,7 +36,10 @@ public Dictionary<string,int> 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(var planet in _planets)
{
result.Add(planet.Key, planet.Key.Length);
}

return result;
}
Expand All @@ -50,9 +53,11 @@ public Dictionary<string,float> OrderedPlanets()
{
return _planets.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
}

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 +72,10 @@ 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