forked from spirit-drive/react-start-template
-
Notifications
You must be signed in to change notification settings - Fork 63
homework_1: homework done #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Anton-CSS
wants to merge
1
commit into
React-js-OTUS:main
Choose a base branch
from
Anton-CSS:homework1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,21 @@ | ||
| // Этот блок кода удалить и раскомментировать код ниже | ||
| it('remove it', () => { | ||
| expect(true).toBe(true); | ||
| }); | ||
| import { transformCustomers } from './1_base'; | ||
|
|
||
| describe('all', () => { | ||
| it('transformCustomers', () => { | ||
| const customers = [ | ||
| { id: 1, name: 'John', age: 25, isSubscribed: true }, | ||
| { id: 2, name: 'Mary', age: 40, isSubscribed: false }, | ||
| { id: 3, name: 'Bob', age: 32, isSubscribed: true }, | ||
| { id: 4, name: 'Alice', age: 22, isSubscribed: true }, | ||
| { id: 5, name: 'David', age: 48, isSubscribed: false }, | ||
| ]; | ||
|
|
||
| // import { transformCustomers } from './1_base'; | ||
| // | ||
| // describe('all', () => { | ||
| // it('transformCustomers', () => { | ||
| // const customers = [ | ||
| // { id: 1, name: 'John', age: 25, isSubscribed: true }, | ||
| // { id: 2, name: 'Mary', age: 40, isSubscribed: false }, | ||
| // { id: 3, name: 'Bob', age: 32, isSubscribed: true }, | ||
| // { id: 4, name: 'Alice', age: 22, isSubscribed: true }, | ||
| // { id: 5, name: 'David', age: 48, isSubscribed: false }, | ||
| // ]; | ||
| // | ||
| // expect(transformCustomers(customers)).toEqual({ | ||
| // 1: { name: 'John', age: 25, isSubscribed: true }, | ||
| // 2: { name: 'Mary', age: 40, isSubscribed: false }, | ||
| // 3: { name: 'Bob', age: 32, isSubscribed: true }, | ||
| // 4: { name: 'Alice', age: 22, isSubscribed: true }, | ||
| // 5: { name: 'David', age: 48, isSubscribed: false }, | ||
| // }); | ||
| // }); | ||
| // }); | ||
| expect(transformCustomers(customers)).toEqual({ | ||
| 1: { name: 'John', age: 25, isSubscribed: true }, | ||
| 2: { name: 'Mary', age: 40, isSubscribed: false }, | ||
| 3: { name: 'Bob', age: 32, isSubscribed: true }, | ||
| 4: { name: 'Alice', age: 22, isSubscribed: true }, | ||
| 5: { name: 'David', age: 48, isSubscribed: false }, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * Нужно превратить файл в ts и указать типы аргументов и типы возвращаемого значения | ||
| * */ | ||
| export const removePlus = (string: string): string => string.replace(/^\+/, ''); | ||
|
|
||
| export const addPlus = (string: string): string => `+${string}`; | ||
|
|
||
| export const removeFirstZeros = (value: string): string => value.replace(/^(-)?[0]+(-?\d+.*)$/, '$1$2'); | ||
|
|
||
| export const getBeautifulNumber = (value: string, separator = ' '): string => | ||
| value?.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator); | ||
|
|
||
| export const round = (value: number, accuracy = 2): number => { | ||
| const d = 10 ** accuracy; | ||
| return Math.round(value * d) / d; | ||
| }; | ||
|
|
||
| const transformRegexp = | ||
| /(matrix\(-?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, -?\d+(\.\d+)?, )(-?\d+(\.\d+)?), (-?\d+(\.\d+)?)\)/; | ||
|
|
||
| type TransformType = { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
|
|
||
| export const getTransformFromCss = (transformCssString: string): TransformType => { | ||
| const data = transformCssString.match(transformRegexp); | ||
| if (!data) return { x: 0, y: 0 }; | ||
| return { | ||
| x: parseInt(data[6], 10), | ||
| y: parseInt(data[8], 10), | ||
| }; | ||
| }; | ||
| //кортеж | ||
| type Tuple = [number, number, number]; | ||
|
|
||
| export const getColorContrastValue = ([red, green, blue]: Tuple) => | ||
| // 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'); | ||
|
|
||
| //Type RegExp trivially inferred from a RegExp literal, remove type annotation. | ||
| // Тип RegExp не требует явной анотации | ||
| export const shortColorRegExp = /^#[0-9a-f]{3}$/i; | ||
| export const longColorRegExp = /^#[0-9a-f]{6}$/i; | ||
|
|
||
| export const checkColor = (color: string): void | never => { | ||
| if (!longColorRegExp.test(color) && !shortColorRegExp.test(color)) throw new Error(`invalid hex color: ${color}`); | ||
| }; | ||
|
|
||
| export const hex2rgb = (color: string): Tuple => { | ||
| checkColor(color); | ||
| if (shortColorRegExp.test(color)) { | ||
| const red = parseInt(color.substring(1, 2), 16); | ||
| const green = parseInt(color.substring(2, 3), 16); | ||
| const blue = parseInt(color.substring(3, 4), 16); | ||
| return [red, green, blue]; | ||
| } | ||
| const red = parseInt(color.substring(1, 3), 16); | ||
| const green = parseInt(color.substring(3, 5), 16); | ||
| const blue = parseInt(color.substring(5, 8), 16); | ||
| return [red, green, blue]; | ||
| }; | ||
|
|
||
| export const getNumberedArray = <T>(arr: Array<T>): { value: T; number: number }[] => | ||
| arr.map((value, number) => ({ value, number })); | ||
|
|
||
| export const toStringArray = (arr: { value: string | number; number: string | number }[]): string[] => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в отдельный тип{ value: string | number; number: string | number }[] |
||
| arr.map(({ value, number }) => `${value}_${number}`); | ||
|
|
||
| type TCustomer = { | ||
| id: number; | ||
| name: string; | ||
| age: number; | ||
| isSubscribed: boolean; | ||
| }; | ||
|
|
||
| type TCustomerMap = { | ||
| [key: TCustomer['id']]: Omit<TCustomer, 'id'>; | ||
| }; | ||
|
|
||
| export const transformCustomers = (customers: Array<TCustomer>): TCustomerMap => { | ||
| return customers.reduce<TCustomerMap>((acc, customer) => { | ||
| acc[customer.id] = { name: customer.name, age: customer.age, isSubscribed: customer.isSubscribed }; | ||
| return acc; | ||
| }, {}); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,30 @@ | ||
| // Этот блок кода удалить и раскомментировать код ниже | ||
| it('remove it', () => { | ||
| expect(true).toBe(true); | ||
| }); | ||
| import { createRandomOperation, createRandomProduct } from './3_write'; | ||
|
|
||
| describe('all', () => { | ||
| it('operation', () => { | ||
| const createdAt = '2023-06-06T12:06:56.957Z'; | ||
| const operation = createRandomOperation(createdAt); | ||
| expect(operation).toHaveProperty('createdAt', createdAt); | ||
| expect(operation).toHaveProperty('id'); | ||
| expect(operation).toHaveProperty('name'); | ||
| expect(operation).toHaveProperty('desc'); | ||
| expect(operation).toHaveProperty('createdAt'); | ||
| expect(operation).toHaveProperty('amount'); | ||
| expect(operation).toHaveProperty('category'); | ||
| expect(operation).toHaveProperty('type'); | ||
| }); | ||
|
|
||
| // import { createRandomOperation, createRandomProduct } from './3_write'; | ||
| // | ||
| // describe('all', () => { | ||
| // it('operation', () => { | ||
| // const createdAt = '2023-06-06T12:06:56.957Z'; | ||
| // const operation = createRandomOperation(createdAt); | ||
| // expect(operation).toHaveProperty('createdAt', createdAt); | ||
| // expect(operation).toHaveProperty('id'); | ||
| // expect(operation).toHaveProperty('name'); | ||
| // expect(operation).toHaveProperty('desc'); | ||
| // expect(operation).toHaveProperty('createdAt'); | ||
| // expect(operation).toHaveProperty('amount'); | ||
| // expect(operation).toHaveProperty('category'); | ||
| // expect(operation).toHaveProperty('type'); | ||
| // }); | ||
| // | ||
| // it('product', () => { | ||
| // const createdAt = '2023-06-06T12:06:56.957Z'; | ||
| // const product = createRandomProduct(createdAt); | ||
| // expect(product).toHaveProperty('createdAt', createdAt); | ||
| // expect(product).toHaveProperty('id'); | ||
| // expect(product).toHaveProperty('name'); | ||
| // expect(product).toHaveProperty('photo'); | ||
| // expect(product).toHaveProperty('desc'); | ||
| // expect(product).toHaveProperty('createdAt'); | ||
| // expect(product).toHaveProperty('oldPrice'); | ||
| // expect(product).toHaveProperty('price'); | ||
| // expect(product).toHaveProperty('category'); | ||
| // }); | ||
| // }); | ||
| it('product', () => { | ||
| const createdAt = '2023-06-06T12:06:56.957Z'; | ||
| const product = createRandomProduct(createdAt); | ||
| expect(product).toHaveProperty('createdAt', createdAt); | ||
| expect(product).toHaveProperty('id'); | ||
| expect(product).toHaveProperty('name'); | ||
| expect(product).toHaveProperty('photo'); | ||
| expect(product).toHaveProperty('desc'); | ||
| expect(product).toHaveProperty('createdAt'); | ||
| expect(product).toHaveProperty('oldPrice'); | ||
| expect(product).toHaveProperty('price'); | ||
| expect(product).toHaveProperty('category'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В отдельный тип { value: T; number: number }[]