Conversation
| .split("") | ||
| .splice(0, 3) | ||
| .join(""); | ||
| let resultPhone = |
| }; | ||
|
|
||
| deleteUser(id) { | ||
| this.database.forEach((elem, index) => { |
There was a problem hiding this comment.
such case would be much better
this.database = this.database.filter( ... )| this.database.splice(index, 1); | ||
| } | ||
| }); | ||
| this.database.splice(); |
| this.database.splice(); | ||
| }; | ||
| searchUserByName(name) { | ||
| return this.database.reduce(function(newElem, elem) { |
There was a problem hiding this comment.
use Array.prototype.filter is fine here and much better than reduce
| editUser(id, options) { | ||
| this.database.map(elem => { | ||
| if (elem.id == id) { | ||
| if (options.name) { |
There was a problem hiding this comment.
Is it possible use don't have such property?
| sortUser(param, direction) { | ||
| return this.database.sort((a, b) => { | ||
| if (direction) { | ||
| if (direction == "big") { |
There was a problem hiding this comment.
what does small/big refer to ? :)
| if (options.name) { | ||
| user.name = options.name; | ||
| } | ||
| if (options.phone) { |
There was a problem hiding this comment.
please omit code duplication, there the same code at line 14
| } | ||
| this.database.push(user); | ||
| }; | ||
| checkPhoneNumber(phone){isNaN(+phone)}; |
| this.database = []; | ||
| } | ||
|
|
||
| addUser (options) { |
There was a problem hiding this comment.
I guess method addUser accepts 'user' as param
| }) | ||
|
|
||
| const myPhoneApp = new PhoneApp(); | ||
| myPhoneApp.addUser(vasya); |
There was a problem hiding this comment.
a pretty interesting decision to create user outside of phoneApp.
But it will be even better to make additional "mental-layer" to create such users. That layer would validate and than send user to phoneApp the main goal of such approach to make sure DATA(users) already validated and we just want to operate with them, without any validation inside internal methods of PhoneApp
| <div class="app-header"> | ||
| My Phone App | ||
| </div> | ||
| <div class='app-content'> |
There was a problem hiding this comment.
you have to use double quotes for attributes, it could cause problems in some browser
| </div> | ||
| <div class='app-content'> | ||
| <div class='app-contact-list'> | ||
| <table class='contact-table' cellspacing="0" cellpadding="0"> |
| // myPhoneApp.editUser(4, { homePhone: "159357" }); | ||
| // console.log(myPhoneApp.filterUser("homePhone")); | ||
| // console.log(myPhoneApp.sortUser("phone", "big")); | ||
| // console.log(myPhoneApp.checkAndFormatPhoneNumber("0993378130")); |
There was a problem hiding this comment.
let clean up it a bit, please remove unused parts of the code
No description provided.