this.users.find(user => user.first === first && user.last === last)
// user || undefined
function UserList() {
this.users = [];
this.has = function(User) {
return this.users.find(u =>
u.firstName === User.firstName
&& u.lastName === User.lastName
) !== undefined
}
this.add = function(User) {
if (this.has(User)) {
throw 'Ошибка. Такой пользователь уже зарегистрирован'
}
this.users.push(User);
}
// ...
}
//...
else {
fullName = fullName.split(' ');
user.firstName = fullName[0];
user.lastName = fullName[1];
try {
userList.add(user);
} catch(e) {
alert(e)
}
}