Loading content…
Loading content…
Given a list of developer profiles containing name, active status, age, and skills, write a JavaScript function that filters out inactive developers, averages the ages of active developers, and returns a sorted list of all active developer skills without duplicates.
Expected Output
A single utility function returning the aggregated telemetry: { activeDevs: string[], averageAge: number, uniqueSkills: string[] }.
Click to toggle the recommended code solution
Architectural Explanation
This function filters the arrays, computes divisions safely, extracts skills via Set, and chains conversions immutably without altering reference structures.Code Snippet
export function transformDevelopers(devs) {
const activeDevs = devs.filter(d => d.active);
if (activeDevs.length === 0) {
return { activeNames: [], averageAge: 0, uniqueSkills: [] };
}
const totalAge = activeDevs.reduce((sum, d) => sum + d.age, 0);
const averageAge = totalAge / activeDevs.length;
const skillsSet = new Set();
activeDevs.forEach(d => {
d.skills.forEach(skill => skillsSet.add(skill));
});
const uniqueSkills = Array.from(skillsSet).sort();
return {
activeNames: activeDevs.map(d => d.name),
averageAge,
uniqueSkills
};
}How to pitch this solution during technical interviews
I process array transformations by chaining pure immutable routines. I aggregate values like average age using reduce, and isolate arrays of lists into a unique, sorted array by leveraging ES6 Set collections.