📅  最后修改于: 2022-03-11 15:00:06.559000             🧑  作者: Mango
function list(names){
if (names.length > 1) {
return `${otherNames(names)} & ${names[names.length - 1].name}`
} else if (names.length === 1) {
return names[0].name
}
return '';
}
function otherNames(array) {
return array.splice(0, array.length - 1).map(person => person.name).join(', ');
}