-
Notifications
You must be signed in to change notification settings - Fork 0
10.07.18 first push #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GeorgeTsendra
wants to merge
2
commits into
master
Choose a base branch
from
callBook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Phone Book</title> | ||
| </head> | ||
| <body> | ||
| <script type="text/javascript" src="js.js"> | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // Приложение телефонный справочник | ||
| // | ||
| // Создайте функцию конструктор. | ||
| // У данной функции должны быть методы: | ||
| // | ||
| // 1 Преобразование телефонного номера из формата 0993378130 в (099) 33-78-130++ | ||
| // 2 Проверка, что телефонный номер содержит только числа ++ | ||
| // 3 Добавление пользователей в справочник ++ | ||
| // 4 Удаление пользователя по имени, фамилии ++ | ||
| // 5 Поиск пользователей по имени - отображает всех пользователей с одинаковым именем ++ | ||
| // 6 Изменение имени, фамилии, телефонного номера у выбраного пользователя ++ | ||
| // 7 Сортировка пользователей по номеру телефона, фамилии, имени и тд, по любому из свойств пользователя++ | ||
| // 8 Фильтр по указанному свойству++ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| function PhoneApp() { | ||
| this.dataBase = [ | ||
| {id:1, name:'Vasya',thername: "Ivanov", numb: `(099)33-78-130`}, | ||
| {id:2, name:'Dima', thername: "Ivanov", numb: `(099)33-78-130`}, | ||
| {id:3, name:'Grisha', thername: "Ivanov", numb: `(099)33-78-130`}, | ||
| {id:4, name:'Jora', thername: "Ivanov", numb: `(099)33-78-130`}, | ||
| {id:5, name:'Jora', thername: "Ivanov", numb: `(099)33-78-130`}, | ||
| ] | ||
| } | ||
|
|
||
| PhoneApp.prototype.editUser = function(name,thername,numb) { | ||
| // проверяем длину номера | ||
| if (numb.length > 10) { | ||
| console.error(`make correct numb`); | ||
| } | ||
| // проверяем содержимое | ||
| for (var i = 0; i < numb.length; i++) { | ||
| var newNumb = +numb[i]; | ||
| if (typeof newNumb != `number` || typeof newNumb == `NaN`) { | ||
| console.error(`not correct numb`); | ||
| continue; | ||
| } | ||
| } | ||
| // формируем корректный формат | ||
| let firstThreeNumb = `${numb[0]}${numb[1]}${numb[2]}`; | ||
| let secondTwoNumb = `${numb[3]}${numb[4]}`; | ||
| let therdTwoNumb = `${numb[5]}${numb[6]}`; | ||
| let fourthThreeNumb = `${numb[7]}${numb[8]}${numb[9]}`; | ||
| let readyNumb = `(${firstThreeNumb})${secondTwoNumb}-${therdTwoNumb}-${fourthThreeNumb}`; | ||
| //формируем ID по длине массива + 1 | ||
| let correctId = this.dataBase.length+1; | ||
|
|
||
| this.dataBase.push({id:correctId,name:name,thername:thername,numb:readyNumb}) // now it is not so long ;) | ||
| } | ||
|
|
||
|
|
||
|
|
||
| PhoneApp.prototype.usersRemovingByThernameAndName = function(username) { | ||
| this.dataBase.forEach((value) => { | ||
| if (value.name == username) { | ||
| this.dataBase = this.dataBase.filter((value) => { | ||
| return value.name != username | ||
| }) | ||
| } | ||
| if (value.thername == username) { | ||
| this.dataBase = this.dataBase.filter((value) => { | ||
|
|
||
| return value.thername != username | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| PhoneApp.prototype.searchUsers = function(username) { | ||
| let allUsers = []; | ||
| this.dataBase.forEach((value, index, arr)=> { | ||
|
|
||
| if (value.name === username) { | ||
| allUsers.push(this.dataBase[index]); | ||
|
|
||
| } | ||
| }) | ||
| console.log(allUsers); | ||
| } | ||
|
|
||
| PhoneApp.prototype.changeUsers = function(userId, name, thername, numb) { | ||
| // проверяем длину номера | ||
| if (numb.length > 10) { | ||
| console.error(`make correct numb`); | ||
| } | ||
| // проверяем содержимое | ||
| for (var i = 0; i < numb.length; i++) { | ||
| var newNumb = +numb[i]; | ||
| if (typeof newNumb != `number` || typeof newNumb == `NaN`) { | ||
| console.error(`not correct numb`); | ||
| continue; | ||
| } | ||
| } | ||
| // формируем корректный формат | ||
| let firstThreeNumb = `${numb[0]}${numb[1]}${numb[2]}`; | ||
| let secondTwoNumb = `${numb[3]}${numb[4]}`; | ||
| let therdTwoNumb = `${numb[5]}${numb[6]}`; | ||
| let fourthThreeNumb = `${numb[7]}${numb[8]}${numb[9]}`; | ||
| let readyNumb = `(${firstThreeNumb})${secondTwoNumb}-${therdTwoNumb}-${fourthThreeNumb}`; | ||
|
|
||
| this.dataBase.forEach((value, index, arr)=> { | ||
| let correctId = index + 1; | ||
| if (value.id == userId) { | ||
| this.dataBase[index] = {id:correctId,name:name,thername:thername,numb:readyNumb};// now it is not so long ;) | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| PhoneApp.prototype.sortUsers = function(property) { | ||
|
|
||
| console.log(property); | ||
| var newArray = this.dataBase.sort((a, b) => { | ||
| return a[property] == b[property] ? 0 : a[property] < b[property] ? -1 : 1;}) | ||
|
|
||
|
|
||
| console.log(newArray); | ||
| } | ||
| PhoneApp.prototype.filterUsers = function(property) { | ||
| let filteredArray = [] | ||
| this.dataBase.filter((value,index,arr)=>{ | ||
| filteredArray.push(`${property}: ${value[property]}`); | ||
| }) | ||
| console.log(filteredArray); | ||
| } | ||
|
|
||
| const myApp = new PhoneApp(); | ||
| myApp.editUser(`Petiya`,`Petrov`, `0993378130`) | ||
| myApp.editUser(`Alex`,`Petrov`, `0093378130`) | ||
| // myApp.usersRemovingByThernameAndName('Petrov') | ||
|
|
||
|
|
||
|
|
||
| console.log(myApp); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тоже подойдет лучше метод filter