Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
return name instead of type
It was meant to return the names , not the types... how to fix it? https://code.sololearn.com/WEeQLqAsWxEF/?ref=app
4 ответов
+ 3
Replace line 52 with this.
const acceptedPeople = getAcceptedPeople(invitedPeople);
for(person of acceptedPeople){
console.log(person.name);
}
+ 3
filter function return an array, even if there are only one item found ^^
+ 3
There are a couple of other ways to approach this too, if you want to change your function to get the accepted people's names and not the person objects.
Method 1 - Reduce:
function getAcceptedPeoplesNames(people) {
return people.filter(canComeToParty).reduce(
(
accumulatedNames,
currentPerson,
index,
peopleList
) => {
const separator = index === peopleList.length -
1 ? "." : ", "
return accumulatedNames + currentPerson.name +
separator
}, "")
}
console.log(getAcceptedPeoplesNames(invitedPeople))
Method 2 - Map & Join:
function getAcceptedPeoplesNames(people) {
return people.filter(canComeToParty).map(person => person.name).join(", ")
}
Then, console log as above.
+ 3
thank you people!