Skip to content

Commit

Permalink
Merge pull request #1 from MastersAcademy/master
Browse files Browse the repository at this point in the history
get last changes
  • Loading branch information
irina-hychka authored Dec 14, 2018
2 parents 5f779f7 + f5af5b7 commit de53a1e
Show file tree
Hide file tree
Showing 683 changed files with 27,337 additions and 1,456 deletions.
100 changes: 100 additions & 0 deletions homeworks/Aleksandr.Turuta_turuta7/homework_6/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// the task 1
const user = {};
Object.defineProperties(user, {
fullName: {
enumerable: true,
configurable: true,
writeble: true,
set: (name) => {
this.fullName = name
.replace(/([[A-Za-z])\S/g, s => s.toLowerCase())
.replace(/(^|\s|[-])\S/g, s => s.toUpperCase());
},
get: () => this.fullName,
},
phone: {
enumerable: true,
configurable: true,
writeble: true,
set: (num) => {
this.phone = num
.replace(/(?![/+])\D+/g, '');
},
get: () => this.phone,
},
});
user.fullName = 'aNna-mAria joHNs';
console.log(user.fullName);
user.phone = '+38(068)77-22-9-44';
console.log(user.phone);

// the task 2
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 stabling = [
{ name: 'Apollo', breed: 'horses1' },
{ name: 'Augustus', breed: 'horses2' },
{ name: 'Aklon', breed: 'horses3' },
{ name: 'Antey', breed: 'horses4' },
{ name: 'Ahill', breed: 'horses5' },
{ name: 'Angel', breed: 'horses6' },
{ name: 'Aston', breed: 'horses7' },
{ name: 'Adonis', breed: 'horses8' },
{ name: 'Bella', breed: 'horses9' },
{ name: 'Bonita', breed: 'horses10' },
];
stabling.forEach((element) => {
this.horses.push(new Racer(element.name, element.breed));
});
}

startRace() {
this.horses.forEach(a => a.run());
for (let i = 0; i < 5; i++) {
setTimeout(() => {
this.horses.forEach((element) => {
console.log(element);
});
}, 2000 * i);
}
setTimeout(() => {
this.horses.sort((a, b) => a.distance - b.distance);
console.log(`Win horse: ${this.horses[0].name}`);
}, 10000);
}
}
const horseRacing = new Race();
horseRacing.createRace();
horseRacing.startRace();
83 changes: 83 additions & 0 deletions homeworks/Alexey.Berkut_AlBerkut/homework_6/horse.js
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();
33 changes: 33 additions & 0 deletions homeworks/Alexey.Berkut_AlBerkut/homework_6/user.js
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);
32 changes: 32 additions & 0 deletions homeworks/Dmytro.Tyshchenko_DmytroTy/homework_6/task1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const user = {};
const SEARCH_WORD = /\b\w/g;
const SEARCH_PHONE_PLUS_AND_DIGIT = /^\+\d+|\d+/g;

function addName(obj) {
let protect;
Object.defineProperty(obj, 'fullName', {
get: () => protect,
set(value) {
protect = value.toLowerCase().replace(SEARCH_WORD, str => str.toUpperCase());
},
enumerable: true,
});
}

function addPhone(obj) {
let protect;
Object.defineProperty(obj, 'phone', {
get: () => protect,
set(value) { protect = value.match(SEARCH_PHONE_PLUS_AND_DIGIT).join(''); },
});
}

addName(user);
addPhone(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)+111b22+33';
console.log(user.phone);
71 changes: 71 additions & 0 deletions homeworks/Dmytro.Tyshchenko_DmytroTy/homework_6/task2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const horsesList = [{ name: 'Big Racket', breed: 'Thoroughbred' }, { name: 'Shareef Dancer', breed: 'Thoroughbred' },
{ name: 'Green Monkey', breed: 'Thoroughbred' }, { name: 'Annihilator', breed: 'Thoroughbred' },
{ name: 'Seattle Dancer', breed: 'Thoroughbred' }, { name: 'Mystic Park', breed: 'Standardbred' },
{ name: 'Pine Chip', breed: 'Standardbred' }, { name: 'Sardar\t', breed: 'Thoroughbred' },
{ name: 'Poetin\t', breed: 'Brandenburger' }, { name: 'Lord Sinclair', breed: 'Bavarian Warmblood' }];

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.setSpeed();
this.time = 0;
}

setSpeed() { this.speed = 10 + 5 * Math.random(); }

run(timeout) {
const intervalID = setInterval(() => {
this.distance += this.speed;
this.time++;
this.setSpeed();

if (this.time >= timeout) clearInterval(intervalID);
}, 1000);
}
}

class Race {
createRace() {
this.horses = horsesList.map(obj => new Racer(obj.name, obj.breed));
}

startRace(timeout) {
this.time = 0;
this.finish = timeout;

this.horses.forEach(obj => obj.run(timeout));

setTimeout(() => {
this.intervalID = setInterval(() => this.logRacing(), 2000);
}, 100);
}

logRacing() {
this.time += 2;

function createLogRacing(str, obj) {
return `${str}${obj.name}\t(${obj.breed})\t\trun\t${obj.distance} m\n`;
}

console.log(this.horses.reduce(createLogRacing, `Time = ${this.time} c:\n`));

if (this.time >= this.finish) {
clearInterval(this.intervalID);
this.horses.sort((a, b) => b.distance - a.distance);
console.log(`Winner: ${this.horses[0].name} congratulate the champion!`);
}
}
}

const race1 = new Race();

race1.createRace();
race1.startRace(10);
34 changes: 34 additions & 0 deletions homeworks/Ivan.Artemenko_IvanArtemenko/homework_6/homework_6_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const user = {};
const reg1 = /\b[a-z]/g;
const reg2 = /^\+\d*|\d/g;
Object.defineProperties(user, {
ollName: {
get() {
return this.name;
},
set(value) {
this.name = value.toLowerCase().replace(reg1, str => str.toUpperCase());
},
enumerable: true,
writeble: true,
configurable: true,
},
userPhone: {
get() {
return this.phone;
},
set(value) {
this.phone = value.match(reg2).join('');
},
enumerable: true,
writeble: true,
configurable: true,
},
});

user.ollName = 'aNNa-maRia Johns';
console.log(user.ollName);
user.userPhone = '+38(096)-448-20-89';
console.log(user.userPhone);
user.userPhone = '+38(096)w448=20+89';
console.log(user.userPhone);
Loading

0 comments on commit de53a1e

Please sign in to comment.