Skip to content

Instantly share code, notes, and snippets.

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