Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
Never
class User {
    idade = 0;
    name = "";
    email = "";
    lastName ="";
    password = "";

    constructor(name, lastName, email){
        this.name = name;
        this.lastName = lastName;
        this.email = email;
    }
}


class UserService {

    users = [];

    addUser(user){
        this.users.push(user);
    }

    removeUser(email){
        this.users.forEach((element, index) => {
            if(element.email === email){
                this.users.splice(index, 1);
            }
        })
    }
    put(newUser, email){
        this.users.forEach((user, index) => {
            if(user.email === email){
                user.name = newUser.name;
                user.lastName = newUser.lastName;
                user.email = newUser.email;
            }
        })
    }
}


const userService = new UserService();

for(let i = 0; i < 10; i++){
    const user = new User("leandro"+i, "guimaraes"+i, "leandro.guimaraes@gmail.com"+i) ;
    userService.addUser(user)
}

userService.removeUser(userService.users[2].email);
console.log(userService.users);