Skip to content

Instantly share code, notes, and snippets.

@creyke
Last active March 26, 2021 09:33
Show Gist options
  • Save creyke/a775badb31773ec74acf402407b1e013 to your computer and use it in GitHub Desktop.
Save creyke/a775badb31773ec74acf402407b1e013 to your computer and use it in GitHub Desktop.
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