SHARE
TWEET

Untitled

a guest Sep 17th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top