Skip to content

Дюкин Петр // ts-2#7

Open
diukin wants to merge 3 commits intoRTF-Angular-2021:masterfrom
diukin:master
Open

Дюкин Петр // ts-2#7
diukin wants to merge 3 commits intoRTF-Angular-2021:masterfrom
diukin:master

Conversation

@diukin
Copy link

@diukin diukin commented Apr 8, 2021

No description provided.

export class MoneyRepository {
private _repository: any;
constructor(initialRepository: any) {
private _repository: Array<object>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object в типизации - страшный грех, также как и any

const rubles = [10, 50, 100, 500, 1000, 5000];
this._repository.forEach(e => {
for (let key in e)
if (e['moneyInfo']['currency'] === currency && temp >= e['count']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обращаться к объекту через скобки и строчную нотацию следует только в одном случае - когда название поля состоит из нескольких слова, но это полная жесть и так никто не делает

public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any {

public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: string): boolean {
return argsForChangeFunction === option[0] ? this.changeUserName(argsForChangeFunction) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Одно тернарное выражение в другом тернарном выражении очень запутывает, не надо так

public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: any): any {

public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit[]): IMoneyUnit[] {
const K = fromCurrency === Currency.RUB ? 70 : 1/70;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Математика в компьютере работает не так как в обычной жизни.
Когда условие попадет во вторую часть тернарного выражения коэффициент будет равен 0.014285714285714285 что сразу сломает все дальнейшие вычисления

public convertMoneyUnits(fromCurrency: Currency, toCurrency: Currency, moneyUnits: IMoneyUnit[]): IMoneyUnit[] {
const K = fromCurrency === Currency.RUB ? 70 : 1/70;
let res: IMoneyUnit[] = [];
for (var e of moneyUnits) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для обхода массива следует использовать методы объекта массива

if (!this._authorizedUser) return false;
this._moneyRepository.takeMoney(moneyUnits);
const sum = moneyUnits.reduce((sum, unit) => {
return sum + unit.count * (+unit.moneyInfo.denomination.match(/\d/g).join(''));}, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неявное преобразование - зло

else this._repository.push(unit);
})
}
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачтено 1 балл

if (typeof user === "undefined") return false
card = user.cards.filter(x => x.id === cardId)[0];
return typeof card !== "undefined" ? cardPin === card.pin : false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 балов

case UserSettingOptions.surname:
return this.changeUserSurname(argsForChangeFunction);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 балл

return moneyUnits.count * denomination * 70;
}
return 0;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 балл

if (this._authorizedUser)
return Boolean(this._currencyConverterModule.convertMoneyUnits(fromCurrency, toCurrency, moneyUnits));
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 балл

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants