Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. var groupedFlights = departingFlights
  2.     .OrderBy(f => f.DepartureDate)
  3.     .Aggregate(
  4.         new Dictionary<DateTime, List<Flight>>(),
  5.         (acc, flight) =>
  6.         {
  7.             var key = acc.Keys.SingleOrDefault(k => IsDateWithin(flight.DepartureDate, k, k.AddMinutes(31)));
  8.             if (key == default)
  9.             {
  10.                 acc.Add(flight.DepartureDate, new List<Flight> { flight });
  11.             }
  12.             else
  13.             {
  14.                 acc[key].Add(flight);
  15.             }
  16.             return acc;
  17.         },
  18.         groups => groups
  19.             .Select(group => new FlightGrouping
  20.             {
  21.                 GroupStart = group.Key,
  22.                 Flights    = group.Value
  23.             }))
  24.     .ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement