Last active
March 26, 2021 09:56
-
-
Save creyke/b15e3e879e2e2a1bc7c630f5865e5526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace MarketSort.Solutions | |
{ | |
class SorterC : ISorter | |
{ | |
public IEnumerable<string> Sort(IEnumerable<string> values) | |
{ | |
return values | |
.ToDictionary(key => | |
{ | |
var split = key.Split('-'); | |
return split.Length == 1 | |
? (-1, -1) | |
: ( | |
Convert.ToInt32(split[0]), | |
Convert.ToInt32(split[1]) | |
); | |
}, val => val) | |
.OrderBy(x => x.Key.Item1) | |
.ThenBy(x => x.Key.Item2) | |
.Select(x => x.Value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment