Group array by value of "author" and saves sum of "likes" as value

PHOTO EMBED

Tue Apr 12 2022 23:58:23 GMT+0000 (Coordinated Universal Time)

Saved by @kremlevmax1989 #javascript #lodash

const mostLikes = (array) => {
  const authorsAndLikesArray = _(array)
    .groupBy("author")
    .map((objs, key) => ({
      author: key,
      totalLikes: _.sumBy(objs, "likes"),
    }))
    .value();
  const sorted = _.sortBy(authorsAndLikesArray, "totalLikes").reverse();
  return sorted
};
content_copyCOPY