Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Contact{
- constructor() {
- this.contacts = []
- }
- getAllContacts(){
- return this.contacts;
- }
- getContactsByID(id){
- return this.contacts.find(contact => contact.id === id);
- }
- createContact(contact){
- contact.id = this.contacts.length + 1;
- this.contacts.push(contact);
- }
- updateContactByID(id, updatedValue){
- let index = this.contacts.findIndex(contact => contact.id === id);
- this.contacts[index].name = updatedValue.name || this.contacts.name;
- this.contacts[index].phone = updatedValue.phone || this.contacts.phone;
- return this.contacts[index];
- }
- deleteContactByID(id){
- let index = this.contacts.findIndex(contact => contact.id === id);
- this.contacts = this.contacts.filter(contact => contact.id !== id);
- }
- }
- module.exports = new Contact()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement