Last active
December 9, 2021 14:13
-
-
Save vladislavaSim/dd38d6d26bc6ec187855182c1a94c725 to your computer and use it in GitHub Desktop.
This file contains 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
class Validator { | |
constructor(string) { | |
this.string = string; | |
} | |
isEmail() { | |
return this.string.includes('@') && this.string.includes('.') | |
} | |
isDate() { | |
return /\d\d\.\d\d\.\d\d/.test(this.string) | |
} | |
isPhone() { | |
return /^(\+380)?[\s\-]?\(?[0-9]{2}\)?[\s\-]?[0-9]{3}[\s\-]?[0-9]{2}[\s\-]?[0-9]{2}$/.test(this.string) | |
} | |
isDomain() { | |
let domainStr = this.string.substring(this.string.indexOf('.'), this.string.length); | |
console.log(domainStr) | |
return /[a-z]/.test(domainStr) && domainStr.length <= 4; | |
} | |
} | |
let email = new Validator('abcsmth.com'); | |
let date = new Validator('23.03.1999'); | |
let tel = new Validator('+380508888788'); | |
let domain = new Validator('test.ua') | |
console.log(email.isEmail()) | |
console.log(date.isDate()) | |
console.log(tel.isPhone()) | |
console.log(domain.isDomain()) | |
//////// | |
class Worker{ | |
#name; | |
#surname | |
#rate; | |
#days; | |
constructor(name, surname, rate, days) { | |
this.#name = name; | |
this.#surname = surname; | |
this.#rate = rate; | |
this.#days = days; | |
} | |
getName() { | |
return this.#name | |
} | |
getSurname() { | |
return this.#surname | |
} | |
getRate() { | |
return this.#rate | |
} | |
getDays() { | |
return this.#days | |
} | |
getSalary() { | |
return this.#rate * this.#days | |
} | |
setRate(rate) { | |
return this.#rate = rate | |
} | |
setDays(days) { | |
return this.#days = days | |
} | |
} | |
let vasya = new Worker('Vasya', 'Pupkin', 12, 5); | |
let petya = new Worker('Petya', 'Sinyak', 11, 12); | |
let sumSalaries = vasya.getSalary() + petya.getSalary(); | |
console.log(vasya.getName()) | |
console.log(petya.getDays()) | |
console.log(vasya.getSalary()) | |
console.log(petya.getSalary()) | |
console.log(sumSalaries) | |
petya.setDays(20); | |
console.log(petya.getDays()) | |
//////// | |
class MyString{ | |
constructor(string) { | |
this.string = string; | |
} | |
reverse() { | |
return this.string.split('').reverse().join('') | |
} | |
ucFirst() { | |
return this.string[0].toUpperCase() + this.string.substring(1, this.string.length) | |
} | |
ucWord() { | |
let array = this.string.split(' '); | |
let res = array.map((item) => { | |
return item[0].toUpperCase() + item.substring(1, item.length) | |
}) | |
return res.join(' ') | |
} | |
} | |
let str = new MyString('hello beautiful world!') | |
let reversed = str.reverse() | |
console.log(reversed) | |
console.log(str.ucFirst()) | |
console.log(str.ucWord()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment