Дюкин Петр // ts-2#7
Conversation
src/task_1/index.ts
Outdated
| export class MoneyRepository { | ||
| private _repository: any; | ||
| constructor(initialRepository: any) { | ||
| private _repository: Array<object>; |
There was a problem hiding this comment.
Object в типизации - страшный грех, также как и any
src/task_1/index.ts
Outdated
| 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'] |
There was a problem hiding this comment.
Обращаться к объекту через скобки и строчную нотацию следует только в одном случае - когда название поля состоит из нескольких слова, но это полная жесть и так никто не делает
src/task_3/index.ts
Outdated
| public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: any): any { | ||
|
|
||
| public changeUserSettings(option: UserSettingOptions, argsForChangeFunction: string): boolean { | ||
| return argsForChangeFunction === option[0] ? this.changeUserName(argsForChangeFunction) : |
There was a problem hiding this comment.
Одно тернарное выражение в другом тернарном выражении очень запутывает, не надо так
src/task_4/index.ts
Outdated
| 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; |
There was a problem hiding this comment.
Математика в компьютере работает не так как в обычной жизни.
Когда условие попадет во вторую часть тернарного выражения коэффициент будет равен 0.014285714285714285 что сразу сломает все дальнейшие вычисления
src/task_4/index.ts
Outdated
| 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) { |
There was a problem hiding this comment.
Для обхода массива следует использовать методы объекта массива
src/task_5/index.ts
Outdated
| 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); |
There was a problem hiding this comment.
Неявное преобразование - зло
| else this._repository.push(unit); | ||
| }) | ||
| } | ||
| } No newline at end of file |
| if (typeof user === "undefined") return false | ||
| card = user.cards.filter(x => x.id === cardId)[0]; | ||
| return typeof card !== "undefined" ? cardPin === card.pin : false; | ||
| } |
| case UserSettingOptions.surname: | ||
| return this.changeUserSurname(argsForChangeFunction); | ||
| } | ||
| } |
| return moneyUnits.count * denomination * 70; | ||
| } | ||
| return 0; | ||
| } |
| if (this._authorizedUser) | ||
| return Boolean(this._currencyConverterModule.convertMoneyUnits(fromCurrency, toCurrency, moneyUnits)); | ||
| return false; | ||
| } |
No description provided.