08.10.2022, 23:04
|
Новичок на форуме
|
|
Регистрация: 08.10.2022
Сообщений: 2
|
|
Помогите решить задачу
Дополни функцию getFriends(users) таким образом, чтобы она возвращала массив друзей всех пользователей (свойство friends). У нескольких пользователей могут быть одинаковые друзья, сделай так, чтобы возвращаемый массив не содержал повторений.
[
{
name: "Moore Hensley",
email: "moorehensley@indexia.com",
eyeColor: "blue",
friends: ["Sharron Pace"],
isActive: false,
balance: 2811,
gender: "male",
age: 37
},
{
name: "Sharlene Bush",
email: "sharlenebush@tubesys.com",
eyeColor: "blue",
friends: ["Briana Decker", "Sharron Pace"],
isActive: true,
balance: 3821,
gender: "female",
age: 34
},
{
name: "Ross Vazquez",
email: "rossvazquez@xinware.com",
eyeColor: "green",
friends: ["Marilyn Mcintosh", "Padilla Garrison", "Naomi Buckner"],
isActive: false,
balance: 3793,
gender: "male",
age: 24
},
{
name: "Elma Head",
email: "elmahead@omatom.com",
eyeColor: "green",
friends: ["Goldie Gentry", "Aisha Tran"],
isActive: true,
balance: 2278,
gender: "female",
age: 21
},
{
name: "Carey Barr",
email: "careybarr@nurali.com",
eyeColor: "blue",
friends: ["Jordan Sampson", "Eddie Strong"],
isActive: true,
balance: 3951,
gender: "male",
age: 27
},
{
name: "Blackburn Dotson",
email: "blackburndotson@furnigeer.com",
eyeColor: "brown",
friends: ["Jacklyn Lucas", "Linda Chapman"],
isActive: false,
balance: 1498,
gender: "male",
age: 38
},
{
name: "Sheree Anthony",
email: "shereeanthony@kog.com",
eyeColor: "brown",
friends: ["Goldie Gentry", "Briana Decker"],
isActive: true,
balance: 2764,
gender: "female",
age: 39
}
]
|
|
08.10.2022, 23:05
|
Новичок на форуме
|
|
Регистрация: 08.10.2022
Сообщений: 2
|
|
Буду благодарен за предоставленный ответ! Заранее спасибо тебе, дружище!
|
|
09.10.2022, 00:00
|
|
Кандидат Javascript-наук
|
|
Регистрация: 16.08.2018
Сообщений: 109
|
|
const Users = [
{
name: "Moore Hensley",
email: "moorehensley@indexia.com",
eyeColor: "blue",
friends: ["Sharron Pace"],
isActive: false,
balance: 2811,
gender: "male",
age: 37
},
{
name: "Sharlene Bush",
email: "sharlenebush@tubesys.com",
eyeColor: "blue",
friends: ["Briana Decker", "Sharron Pace"],
isActive: true,
balance: 3821,
gender: "female",
age: 34
},
{
name: "Ross Vazquez",
email: "rossvazquez@xinware.com",
eyeColor: "green",
friends: ["Marilyn Mcintosh", "Padilla Garrison", "Naomi Buckner"],
isActive: false,
balance: 3793,
gender: "male",
age: 24
},
{
name: "Elma Head",
email: "elmahead@omatom.com",
eyeColor: "green",
friends: ["Goldie Gentry", "Aisha Tran"],
isActive: true,
balance: 2278,
gender: "female",
age: 21
},
{
name: "Carey Barr",
email: "careybarr@nurali.com",
eyeColor: "blue",
friends: ["Jordan Sampson", "Eddie Strong"],
isActive: true,
balance: 3951,
gender: "male",
age: 27
},
{
name: "Blackburn Dotson",
email: "blackburndotson@furnigeer.com",
eyeColor: "brown",
friends: ["Jacklyn Lucas", "Linda Chapman"],
isActive: false,
balance: 1498,
gender: "male",
age: 38
},
{
name: "Sheree Anthony",
email: "shereeanthony@kog.com",
eyeColor: "brown",
friends: ["Goldie Gentry", "Briana Decker"],
isActive: true,
balance: 2764,
gender: "female",
age: 39
}
];
function getFriends(users) {
var friends = new Set();
for(const user of users) {
for(const friend of user.friends) {
friends.add(friend);
}
}
return Array.from(friends);
}
console.log(getFriends(Users));
|
|
|
|