-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MastersAcademy/master
Master
- Loading branch information
Showing
152 changed files
with
10,050 additions
and
1,058 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class Horse { | ||
constructor(name, breed) { | ||
this.name = name; | ||
this.breed = breed; | ||
} | ||
} | ||
|
||
class Racer extends Horse { | ||
constructor(name, breed) { | ||
super(name, breed); | ||
this.distance = 0; | ||
this.speed = 0; | ||
} | ||
|
||
setSpeed() { | ||
this.speed = Math.floor(Math.random() * 5) + 10; | ||
} | ||
|
||
run() { | ||
this.timer = setInterval(() => { | ||
this.distance += this.speed; | ||
this.setSpeed(); | ||
}, 1000); | ||
} | ||
|
||
stop() { | ||
if (this.timer) clearInterval(this.timer); | ||
} | ||
} | ||
|
||
class Race { | ||
constructor() { | ||
this.horses = []; | ||
} | ||
|
||
createRace(horses) { | ||
this.horses = horses; | ||
} | ||
|
||
startRace() { | ||
if (this.horses.length) { | ||
this.horses.forEach(horse => horse.run()); | ||
this.logRacerState(); | ||
setTimeout(this.stopRace.bind(this), 10000); | ||
} | ||
} | ||
|
||
logRacerState() { | ||
this.timer = setInterval(() => { | ||
this.horses.forEach((horse) => { | ||
console.log(`${horse.breed} ${horse.name} : ${horse.distance}`); | ||
}); | ||
}, 2000); | ||
} | ||
|
||
stopRace() { | ||
if (this.timer) clearInterval(this.timer); | ||
this.horses.forEach(horse => horse.stop()); | ||
console.log(this.findWinner().breed, this.findWinner().name, 'Win!'); | ||
} | ||
|
||
findWinner() { | ||
this.horses.sort((i1, i2) => i1.distance - i2.distance); | ||
return this.horses[0]; | ||
} | ||
} | ||
|
||
const HORSES = [ | ||
new Racer('Roach', 'Geralt\'s Horse'), | ||
new Racer('Pegasus', 'Dandelion\'s white gelding'), | ||
new Racer('Aard', 'Windhorse'), | ||
new Racer('Ignis', 'Firehorse'), | ||
new Racer('Quen', 'Battlehorse'), | ||
new Racer('Axii', 'Calmhorse'), | ||
new Racer('Yrden', 'Magichorse'), | ||
new Racer('Kelpie', 'Ciri\'s Horse'), | ||
new Racer('Scorpion', 'Eskel\'s horse'), | ||
new Racer('Lexa', 'Student'), | ||
]; | ||
|
||
const race = new Race(); | ||
race.createRace(HORSES); | ||
race.startRace(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const NAME_FILTER = /\b\w/g; | ||
const PHONE_FILTER = /(?![/+])\D+/g; | ||
|
||
function User() { | ||
let fullName; | ||
let phone; | ||
Object.defineProperties(this, { | ||
fullName: { | ||
set(name) { | ||
fullName = name.toLowerCase().replace(NAME_FILTER, l => l.toUpperCase()); | ||
}, | ||
get() { | ||
return fullName; | ||
}, | ||
}, | ||
phone: { | ||
set(phoneNum) { | ||
phone = phoneNum.replace(PHONE_FILTER, ''); | ||
}, | ||
get() { | ||
return phone; | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
const user = new User(); | ||
user.fullName = 'aNna-mAria joHNs'; | ||
console.log(user.fullName); | ||
user.phone = '+38(096)-111-22-33'; | ||
console.log(user.phone); | ||
user.phone = '38(096)-111b-22-33'; | ||
console.log(user.phone); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const users = {}; | ||
const phone = {}; | ||
function userObjects(user) { | ||
let fullName; | ||
let phoneNumber; | ||
Object.defineProperties(users, { | ||
fullName: { | ||
set(name) { | ||
fullName = name.toString().toLowerCase().replace(/\b\w/g, value => value.toUpperCase()); | ||
}, | ||
get() { | ||
return fullName; | ||
}, | ||
}, | ||
}); | ||
Object.defineProperties(phone, { | ||
phoneNumber: { | ||
set(numPhone) { | ||
phoneNumber = '+'.concat(numPhone.toString().replace(/\D/g, '')); | ||
}, | ||
get() { | ||
return phoneNumber; | ||
}, | ||
}, | ||
}); | ||
return user; | ||
} | ||
const user = userObjects({}); | ||
user.fullName = 'aNna-mAria joHNs'; | ||
console.log(user.fullName); | ||
user.phone = '+38(096)-111-22-33'; | ||
console.log(user.phone); | ||
user.phone = '38(096)-111-22-33'; | ||
console.log(user.phone); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class Horse { | ||
constructor(name, breed) { | ||
this.name = name; | ||
this.breed = breed; | ||
} | ||
} | ||
class Racer extends Horse { | ||
constructor(name, breed) { | ||
super(name, breed); | ||
this.distance = 0; | ||
this.speed = 0; | ||
this.setSpeed(); | ||
} | ||
|
||
setSpeed() { | ||
this.speed = Math.floor(Math.random() * (15 - 10) + 10); | ||
} | ||
|
||
run() { | ||
for (let i = 0; i < 10; i++) { | ||
setTimeout(() => { | ||
this.distance += this.speed; | ||
this.setSpeed(); | ||
console.log(this); | ||
}, 1000 * i); | ||
} | ||
} | ||
} | ||
class Race { | ||
constructor() { | ||
this.horses = []; | ||
} | ||
|
||
createRace() { | ||
const normalize = [ | ||
{ name: 'Buck', breed: 'Zebra' }, | ||
{ name: 'Widowmaker', breed: 'Pony' }, | ||
{ name: 'Cyril Proudbottom', breed: 'Arabian' }, | ||
{ name: 'Snowball', breed: 'Przewalski' }, | ||
{ name: 'Ahill', breed: 'Zebra' }, | ||
{ name: 'Tagged', breed: 'Arabian' }, | ||
{ name: 'Captain', breed: 'Przewalski' }, | ||
{ name: 'Han', breed: 'Arabian' }, | ||
{ name: 'Major', breed: 'Arabian' }, | ||
{ name: 'Max', breed: 'Pony' }, | ||
]; | ||
normalize.forEach((value) => { | ||
this.horses.push(new Racer(value.name, value.breed)); | ||
}); | ||
} | ||
|
||
startRace() { | ||
this.horses.forEach(value => value.run()); | ||
for (let i = 0; i < 5; i++) { | ||
setTimeout(() => { | ||
this.horses.forEach(value => console.log(value)); | ||
}, 2000 * i); | ||
} | ||
setTimeout(() => { | ||
this.horses.sort((value1, value2) => value2.distance - value1.distance); | ||
console.log(`Winner: ${this.horses[0].name}`); | ||
}, 10000); | ||
} | ||
} | ||
const horseRacing = new Race(); | ||
horseRacing.createRace(); | ||
horseRacing.startRace(); |
32 changes: 32 additions & 0 deletions
32
homeworks/denis.yeromenko_Denis-Yeromenko/homework_6/homework_6_1.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const user = {}; | ||
Object.defineProperties(user, { | ||
fullName: { | ||
get() { | ||
return this.userFullName; | ||
}, | ||
set(value) { | ||
const re = /\b\w/g; | ||
this.userFullName = value.trim().toLowerCase().replace(re, str => str.toUpperCase()); | ||
}, | ||
}, | ||
phone: { | ||
get() { | ||
return this.userPhone; | ||
}, | ||
set(value) { | ||
const re = /^\+[\d]*|\d/g; | ||
this.userPhone = value.trim().match(re).join(''); | ||
}, | ||
}, | ||
}); | ||
|
||
user.fullName = ' aLi-Ibn-haTab kiziLbek jr.'; | ||
console.log(user.fullName); | ||
user.fullName = 'aNna-mAria joHNs'; | ||
console.log(user.fullName); | ||
user.phone = ' +32df113256'; | ||
console.log(user.phone); | ||
user.phone = '+38(096)-111-22-33'; | ||
console.log(user.phone); | ||
user.phone = '38(096)+111b22+33'; | ||
console.log(user.phone); |
Oops, something went wrong.