Group endorsements by skill with endorsing users and counts
You are given an array of skill endorsements, where each endorsement is represented by an object that includes a skill and the user who endorsed it. Your task is to write a function, aggregateSkillEndorsements, that processes this array and produces a summary for each skill. To aggregate skill endorsements, Array.prototype.reduce() is a natural fit.
This summary should include the skill name, an array of users who have endorsed the skill, and the total count of endorsements the skill has received. The primary challenge lies in efficiently aggregating this information from a potentially large and unorganized list of endorsements.
Input: An array of endorsement objects, where each object has skill and user properties.
Output: An array of objects, each representing a skill summary that contains the skill name, an array of unique users who endorsed it, and the total count of endorsements for that skill.
Example:
const endorsements = [
{ skill: 'css', user: 'Bill' },
{ skill: 'javascript', user: 'Chad' },
{ skill: 'javascript', user: 'Bill' },
{ skill: 'css', user: 'Sue' },
{ skill: 'javascript', user: 'Sue' },
{ skill: 'html', user: 'Sue' }
];
const skillSummaries = aggregateSkillEndorsements(endorsements);
// Output:
// [
// { skill: 'javascript', users: ['Chad', 'Bill', 'Sue'], count: 3 },
// { skill: 'css', users: ['Bill', 'Sue'], count: 2 },
// { skill: 'html', users: ['Sue'], count: 1 }
// ]
The function must efficiently traverse the endorsements array, grouping endorsements by skill while keeping track of the unique users and total count for each skill. This task tests your ability to manipulate and aggregate data from complex data structures, a common requirement in software development.
skill and user.skill property is a string representing the name of the skill.user property is a string representing the name of the user who endorsed the skill.skill name, an array of users who endorsed the skill (with no duplicates), and the count of total endorsements for that skill.