Homework1#104
Conversation
| 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 => |
There was a problem hiding this comment.
value? подразумевает что может прийти null, поэтому входные null, а раз может прийти null, значит может и вернутся null;
| const transformRegexp = | ||
| /(matrix\(-?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, )(-?\d+(\.\d+)?), (-?\d+(\.\d+)?)\)/; | ||
|
|
||
| export const getTransformFromCss = (transformCssString: string): { x: number; y: number } => { |
There was a problem hiding this comment.
{ x: number; y: number } стоит вынести в отдельный тип
| // 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'); |
There was a problem hiding this comment.
можно сделать сужение типа "black" | "white"
There was a problem hiding this comment.
В теории можно, только не очень понятно зачем)
| export const checkColor = (color: string): void | Error => { | ||
| if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`); | ||
| }; |
There was a problem hiding this comment.
| 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}`); | |
| }; |
There was a problem hiding this comment.
Почему 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 => { |
There was a problem hiding this comment.
Потому hex2rgb вызывает функцию checkColor которая может сгенерировать исключение Error;
|
|
||
| export const getNumberedArray = (arr: []): valueNumber[] => | ||
| arr.map((value: number, number: number) => ({ value, number })); | ||
| export const toStringArray = (arr: []): string[] => arr.map(({ value, number }) => `${value}_${number}`); |
There was a problem hiding this comment.
Объявление пустого массива, следовательно тип Array, в связи с очевидностью записи arr: Array = [], опускаем слово Array; Или имеется в виду что нужно было типизировать сам массив, аля arr: Array ?
Task: TypeScript (1)
6391337
Score: 10 / 10
Полное выполнение задания (3 балла):
Соответствие типов (3 балла):
Отсутствие ошибок (3 балла):
Качество кода (1 балл):