Anton6677, если нужно понять, то:
function sortByAttackType(heroes, attackType) {
return heroes.filter(function(hero) {
return hero.attack_type === attackType;
});
}
function sortByRole(heroes, role) {
return heroes.filter(function(hero) {
return hero.role === role;
});
}
var heroes = [
{ name: 'Anti-Mage', role: 'carry', attack_type: 'melee' },
{ name: 'Wraith King', role: 'carry', attack_type: 'melee' },
{ name: 'Tinker', role: 'carry', attack_type: 'ranged' },
{ name: 'Invoker', role: 'carry', attack_type: 'ranged' },
{ name: 'Ogre Magi', role: 'support', attack_type: 'melee' },
{ name: 'Abaddon', role: 'support', attack_type: 'melee' },
{ name: 'Crystal Maiden', role: 'support', attack_type: 'ranged' },
{ name: 'Disruptor', role: 'support', attack_type: 'ranged' },
];
var carries = sortByRole(heroes, 'carry'),
supports = sortByRole(heroes, 'support'),
melee = sortByAttackType(heroes, 'melee'),
ranged = sortByAttackType(heroes, 'ranged'),
meleeSupports = sortByRole(melee, 'support');
console.log(carries);
console.log(supports);
console.log(melee);
console.log(ranged);
console.log(meleeSupports);