-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.cs
28 lines (22 loc) · 809 Bytes
/
Order.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Link to kata: https://www.codewars.com/kata/55c45be3b2079eccff00010f
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public static class Kata
{
public static string Order(string words)
{
if (String.IsNullOrEmpty(words))
return string.Empty;
string[] tokens = words.Split(' ');
Dictionary<int, string> sentenceOrders = new Dictionary<int, string>();
foreach (string token in tokens)
{
int sentenceOrder = Int32.Parse(Regex.Match(token, @"\d+").Value);
sentenceOrders.Add(sentenceOrder, token);
}
List<string> sentenceList = sentenceOrders.OrderBy(s => s.Key).Select(v => v.Value).ToList();
return String.Join(' ', sentenceList);
}
}