Skip to content

Homework1#104

Open
Chaosito wants to merge 5 commits into
React-js-OTUS:mainfrom
Chaosito:homework1
Open

Homework1#104
Chaosito wants to merge 5 commits into
React-js-OTUS:mainfrom
Chaosito:homework1

Conversation

@Chaosito
Copy link
Copy Markdown

@Chaosito Chaosito commented Dec 23, 2025

  1. Task: TypeScript (1)

  2. 6391337

  3. Score: 10 / 10

  4. Полное выполнение задания (3 балла):

  • Первая часть полностью выполнена.
  • Вторая часть полностью выполнена.
  • Третья часть полностью выполнена.

Соответствие типов (3 балла):

  • В первой части корректно указаны все типы.
  • Во второй части исправлены все ошибки типов.
  • В третьей части корректно описаны типы и написаны функции.

Отсутствие ошибок (3 балла):

  • Нет синтаксических ошибок.
  • Нет логических ошибок, связанных с типами.
  • Код успешно компилируется и работает без ошибок.

Качество кода (1 балл):

  • Код структурирован и читаем.

export const addPlus = (string: string | number): string => `+${string}`;
export const removeFirstZeros = (value: string): string => value.replace(/^(-)?[0]+(-?\d+.*)$/, '$1$2');

export const getBeautifulNumber = (value: string | null, separator = ' '): string | null =>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Зачем тут null?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

value? подразумевает что может прийти null, поэтому входные null, а раз может прийти null, значит может и вернутся null;

Comment thread src/homeworks/ts1/1_base.ts Outdated
const transformRegexp =
/(matrix\(-?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, )(-?\d+(\.\d+)?), (-?\d+(\.\d+)?)\)/;

export const getTransformFromCss = (transformCssString: string): { x: number; y: number } => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

{ x: number; y: number } стоит вынести в отдельный тип

Comment thread src/homeworks/ts1/1_base.ts Outdated
// http://www.w3.org/TR/AERT#color-contrast
Math.round((red * 299 + green * 587 + blue * 114) / 1000);

export const getContrastType = (contrastValue: number): string => (contrastValue > 125 ? 'black' : 'white');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно сделать сужение типа "black" | "white"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

В теории можно, только не очень понятно зачем)

Comment on lines +37 to +39
export const checkColor = (color: string): void | Error => {
if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
export const checkColor = (color: string): void | Error => {
if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`);
};
export const checkColor = (color: string): void | never => {
if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`);
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Почему never? мы же можем получить на выходе только Error, который можем потом поймать в Try..Catch ?

if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`);
};

export const hex2rgb = (color: string): [red: number, green: number, blue: number] | Error => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Почему error?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Потому hex2rgb вызывает функцию checkColor которая может сгенерировать исключение Error;

Comment thread src/homeworks/ts1/1_base.ts Outdated

export const getNumberedArray = (arr: []): valueNumber[] =>
arr.map((value: number, number: number) => ({ value, number }));
export const toStringArray = (arr: []): string[] => arr.map(({ value, number }) => `${value}_${number}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arr: [] ????

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Объявление пустого массива, следовательно тип Array, в связи с очевидностью записи arr: Array = [], опускаем слово Array; Или имеется в виду что нужно было типизировать сам массив, аля arr: Array ?

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.

2 participants