Skip to content Skip to sidebar Skip to footer

Multi Level Groupby Ramda Js

I have been trying to use group by at multiple levels so that the object is grouped by tag, folder and report keys. I was able to groupby at single level but could not proceed furt

Solution 1:

There might be a better/built in solution, but you can use map to group the "inner lists" of your objects like so:

constdata= [
  { letter:"a", number:1, bool:true },
  { letter:"a", number:2, bool:true },
  { letter:"a", number:2, bool:false },
  { letter:"b", number:1, bool:true },
  { letter:"b", number:1, bool:false },
  { letter:"b", number:1, bool:false },
  { letter:"c", number:1, bool:true },
  { letter:"c", number:2, bool:true },
  { letter:"c", number:2, bool:false },
  { letter:"c", number:2, bool:true },
];constgroupByLetterNumberBool=pipe(groupBy(prop("letter")),map(groupBy(prop("number"))),map(map(groupBy(prop("bool")))));groupByLetterNumberBool(data);

Working example here.

Post a Comment for "Multi Level Groupby Ramda Js"