БО
Size: a a a
БО
БО
SS
БО
БО
SS
БО
F
bz
undefined
. Спасибо ! const wizardss = [
{
name: 'Harry Potter',
house: 'Gryfindor'
},
{
name: 'Tonks',
house: 'Hufflepuff'
}];
const pointss = {
HarryPotter: 500,
CedricDiggory: 750,
};
function getPoints(points, wizards) {
return wizards.reduce((arr, wizard, i) => {
const wizardName = wizard.name.split(" ").join('');
const helpArray = [];
if (points[wizardName]) {
const wizHouse = wizards[i].house;
const point = { wizHouse, earned: points[wizardName], i };
helpArray.push(point);
console.log(helpArray[i]); // вывидет первый обьект , а потом undefied . почему undefined ?
}
return arr;
}, []);
}
getPoints(pointss, wizardss);
j
AB
bz
bz
F
AB
AB
j
wizards[i].house === wizard.house
IM
AB
const wizardss = [
{
name: "Harry Potter",
house: "Gryfindor"
},
{
name: "Cedric Diggory",
house: "Hufflepuff"
},
{
name: "Cedric Diggor",
house: "Hufflepuff"
}
];
const pointss = {
"Harry Potter": 500,
"Cedric Diggory": 750,
"Cedric Diggor": 750
};
function getPoints(points, wizards) {
return wizards.reduce((acc, wizard, i) => {
if (points[wizard.name]) {
acc[wizard.house] ??= {
withHouse: wizard.house,
earned: 0,
i
};
acc[wizard.house].earned += points[wizard.name];
}
return acc;
}, {});
}
console.log(getPoints(pointss, wizardss));