Last active
March 26, 2021 09:33
-
-
Save creyke/a775badb31773ec74acf402407b1e013 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.Collections.Generic; | |
using System.Linq; | |
namespace MarketSort.Solutions | |
{ | |
class SorterA : ISorter | |
{ | |
public IEnumerable<string> Sort(IEnumerable<string> values) | |
{ | |
return values | |
.GroupBy(x => x.Last() != '-' && x.Split('-').All(y => int.TryParse(y, out _))) | |
.OrderBy(x => x.Key) | |
.SelectMany(x => x.Key | |
? x | |
.Select(y => (n: y, c: y.Split('-').Select(z => int.Parse(z)))) | |
.OrderBy(y => y.c.First()) | |
.ThenBy(y => y.c.ElementAt(1)) | |
.Select(x => x.n) | |
: x. | |
OrderBy(y => y)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment