Malleys,
но нет проверки "если друзей нет, берём следующего из основного массива"
var persons = [
{ name: 'Ali', close: ['Arno'] },
{ name: 'San', close: ['Vasil', 'Zena'] },
{ name: 'Vasil', close: ['San', 'Ali'] },
{ name: 'Wog', close: ['Zena', 'Ali'] },
{ name: 'Zena', close: ['Sun', 'Wog'] }
];
function placeGuests(guests) {
const placedGuests = []
const next = guest => Array.from(guest.close).sort()
.map(name => guests.find(guest => guest.name === name))
.find(person => person && !placedGuests.includes(person))
for(let guest = guests[0]; guest != null; guest = next(guest)) {
placedGuests.push(guest)
}
return placedGuests
}
console.log(placeGuests(persons));