LINQifies the application.
This commit is contained in:
parent
cf4c025246
commit
969e37b11d
1 changed files with 12 additions and 15 deletions
|
|
@ -6,23 +6,20 @@ string jsonString = File.ReadAllText(fileName);
|
||||||
List<Data> data = JsonSerializer.Deserialize<List<Data>>(jsonString)!;
|
List<Data> data = JsonSerializer.Deserialize<List<Data>>(jsonString)!;
|
||||||
|
|
||||||
var giftLines = data
|
var giftLines = data
|
||||||
.Select(d => $"{Helpers.Numerals[d.Day - 1]} {d.Gift} {d.Context}".Trim());
|
.Select(d => (d.Day, $"{Helpers.Numerals[d.Day - 1]} {d.Gift} {d.Context}".Trim()));
|
||||||
|
var verses = giftLines.Select(l =>
|
||||||
foreach(int day in Enumerable.Range(1, giftLines.Count()))
|
|
||||||
{
|
{
|
||||||
Console.WriteLine($"On the {Helpers.Ordinals[day - 1]} day of Christmas my true love gave to me:");
|
var giftList = giftLines
|
||||||
foreach (var line in giftLines.Take(day).Reverse())
|
.Take(l.Day)
|
||||||
{
|
.Reverse()
|
||||||
if (day > 1 && line == giftLines.First())
|
.Select((line, index) =>
|
||||||
Console.Write("and ");
|
(line, index == l.Day - 1 && l.Day > 1 ? "and " : ""))
|
||||||
|
.Select(t => $"{t.Item2}{t.line.Item2}");
|
||||||
|
|
||||||
if(day == 5)
|
return $"On the {Helpers.Ordinals[l.Day - 1]} day of Christmas my true love gave to me:{Environment.NewLine}{string.Join($",{Environment.NewLine}", giftList)}.{Environment.NewLine}";
|
||||||
Console.WriteLine(line.ToUpper());
|
});
|
||||||
else
|
|
||||||
Console.WriteLine(line);
|
verses.ToList().ForEach(Console.WriteLine);
|
||||||
}
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Press any key to exit…");
|
Console.WriteLine("Press any key to exit…");
|
||||||
Console.Read();
|
Console.Read();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue