|
|
|
|
|
by syntheticcdo
1361 days ago
|
|
Do your co-workers use lodash's chain functionality? I've found it useful to achieve kouteiheika's ideal from the current top comment, with top to bottom readability without too much mental overhead. As an example, given: const sales = [ {month: "Jan", day: 1, total: 120 }, ... ]
You could determine, say, the highest sales day of a given month as follows: const highestSalesDayByMonth = _.chain(sales)
.groupBy("month")
.mapValues((salesForMonth) => _.maxBy(salesForMonth, "total"))
.mapValues("total")
.value()
// highestSalesDayByMonth = { Jan: 140, Feb: 90, ... }
Naturally, minimizing the complexity of the iteratee functions and carefully naming of their arguments is very important to ease debuggability. |
|