This will be a nice feature of TripTime:
As a user, I want to be able to generate and download a pdf for the plan of my trip, so that I can carry my plan around and share with my friends.
The best organisation of the pdf would be in the order of date. So, I have an array of activities and an array of travels. I want them to be grouped by dates, and these groups should be in order as well. Sounds like a couple of intimidating iterations to me on first thought.
Luckily there’s a js package, underscore that provides a range of functional programming helpers.
1 | function groupByDay(events) { |
chain
Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is called.
groupBy
Splits a collection into sets, grouped by the result of running each value through iteratee. If iteratee is a string instead of a function, groups by the property named by iteratee on each of the values.
map
Produces a new array of values by mapping each value in list through a transformation function (iteratee).
sortBy
Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iteratee. iteratee may also be the string name of the property to sort by (eg. length).