by syntheticcdo · 4y ago · 0 comments
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.No comments yet.