"use strict";
class City {
constructor(name, point = 0) {
this.point = point;
this.name = name;
}
go(to) {
const full = Math.abs(to.point - this.point);
let steps = [
{ 'step': 999, 'price': 0.5, 'discount': 0, },
{ 'step': 1999, 'price': 0.5, 'discount': 10 },
{ 'step': 2000, 'price': 0.5, 'discount': 20 },
];
let prices = [0, 0, 0];
for (var i = 0; i < full; i++) {
if (i < steps[0].step) {
prices[0] = steps[0].discount === 0 ? prices[0] + steps[0].price : prices[0] + (steps[0].price - ((steps[0].price / 100) * steps[0].discount));
}
else if (i < steps[1].step) {
prices[1] = steps[1].discount === 0 ? prices[1] + steps[1].price : prices[1] + (steps[1].price - ((steps[1].price / 100) * steps[1].discount));
}
else {
prices[2] = steps[2].discount === 0 ? prices[2] + steps[2].price : prices[2] + (steps[2].price - ((steps[1].price / 100) * steps[2].discount));
}
}
console.log(prices); //Для проверки каждого отрезка
return (prices[0] + prices[1] + prices[2]).toFixed(2);
}
}
const a = new City('A');
const b = new City('Б', 1100);
console.log(a.go(b));