const data = [
{
gender: 'male',
age: 24,
},
{
gender: 'male',
age: 25,
},
{
gender: 'female',
age: 27,
},
{
gender: 'female',
age: 22,
},
{
gender: 'male',
age: 29,
},
];
function getOnlyMales(data) {
return data.filter(function (d) {
return d.gender === 'male';
});
}
function getOnlyAges(data) {
return data.map(function (d) {
return d.age;
});
}
function getAverage(data) {
const sum = data.reduce(function (acc, cur) {
return acc + cur;
}, 0);
return sum / data.length;
}
function compose(...funcArgs) {
return function (data) {
let result = data;
for (let i = 0; i < funcArgs.length; i++) {
result = funcArgs[i](result);
}
return result;
};
}
const getAverageAgeOfMale = compose(
getOnlyMales,
getOnlyAges,
getAverage
);
const result = getAverageAgeOfMale(data);
console.log(result);
참고문헌
Experience luxury par excellent with Delhi Escorts Service; the beautiful damsels are not only head-turners but offer some of the finest discreet services that will elevate your stay in the city.