return name instead of type | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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

26th Mar 2021, 9:52 PM
Boyan Ivanov
Boyan Ivanov - avatar
4 ответов
+ 3
Replace line 52 with this. const acceptedPeople = getAcceptedPeople(invitedPeople); for(person of acceptedPeople){ console.log(person.name); }
26th Mar 2021, 10:12 PM
Avinesh
Avinesh - avatar
+ 3
filter function return an array, even if there are only one item found ^^
26th Mar 2021, 10:00 PM
visph
visph - avatar
+ 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.
27th Mar 2021, 12:07 AM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 3
thank you people!
27th Mar 2021, 1:09 AM
Boyan Ivanov
Boyan Ivanov - avatar