style(*): Apply formatting in markdown files (#76)

This commit is contained in:
Dongho Kim 2024-06-19 17:29:50 +09:00 committed by GitHub
parent 3cc1a03519
commit cfc47e4b83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 91 additions and 64 deletions

View File

@ -5,7 +5,7 @@
## 인터페이스
```typescript
function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[]
function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];
```
### 파라미터

View File

@ -5,7 +5,7 @@
## 인터페이스
```typescript
function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[]
function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
```
### 파라미터

View File

@ -7,7 +7,7 @@
## 인터페이스
```typescript
function maxBy<T>(elements: T[], selector: (element: T) => number): T
function maxBy<T>(elements: T[], selector: (element: T) => number): T;
```
### 파라미터
@ -22,6 +22,6 @@ function maxBy<T>(elements: T[], selector: (element: T) => number): T
### 예시
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a) // 결과: { a: 3 }
maxBy([], x => x.a) // 결과: undefined
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 결과: { a: 3 }
maxBy([], x => x.a); // 결과: undefined
```

View File

@ -7,7 +7,7 @@
## 인터페이스
```typescript
function minBy<T>(elements: T[], selector: (element: T) => number): T
function minBy<T>(elements: T[], selector: (element: T) => number): T;
```
### 파라미터
@ -22,6 +22,6 @@ function minBy<T>(elements: T[], selector: (element: T) => number): T
### 예시
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a) // 결과: { a: 3 }
maxBy([], x => x.a) // 결과: undefined
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 결과: { a: 3 }
maxBy([], x => x.a); // 결과: undefined
```

View File

@ -7,7 +7,10 @@
## 인터페이스
```typescript
function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
function omitBy<T extends Record<string, any>>(
obj: T,
shouldOmit: (value: T[keyof T], key: keyof T) => boolean
): Partial<T>;
```
### 파라미터

View File

@ -5,7 +5,7 @@ Returns a new array containing only the unique elements from the original array,
## Signature
```typescript
function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[]
function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];
```
### Parameters

View File

@ -5,7 +5,7 @@ Returns a new array containing only the unique elements from the original array,
## Signature
```typescript
function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[]
function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
```
### Parameters

View File

@ -7,7 +7,7 @@ If the list is empty, returns `undefined`.
## Signature
```typescript
function maxBy<T>(elements: T[], selector: (element: T) => number): T
function maxBy<T>(elements: T[], selector: (element: T) => number): T;
```
### Parameters
@ -22,6 +22,6 @@ The first element of the list that has the maximum value of the function. If the
### Example
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a) // Returns: { a: 3 }
maxBy([], x => x.a) // Returns: undefined
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
maxBy([], x => x.a); // Returns: undefined
```

View File

@ -7,7 +7,7 @@ If the list is empty, returns `undefined`.
## Signature
```typescript
function minBy<T>(elements: T[], selector: (element: T) => number): T
function minBy<T>(elements: T[], selector: (element: T) => number): T;
```
### Parameters
@ -22,6 +22,6 @@ The first element of the list that has the minimum value of the function. If the
### Example
```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a) // Returns: { a: 1 }
minBy([], x => x.a) // Returns: undefined
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
minBy([], x => x.a); // Returns: undefined
```

View File

@ -8,7 +8,10 @@ includes only the properties for which the predicate function returns false.
## Signature
```typescript
function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
function omitBy<T extends Record<string, any>>(
obj: T,
shouldOmit: (value: T[keyof T], key: keyof T) => boolean
): Partial<T>;
```
### Parameters

View File

@ -19,7 +19,11 @@
* const result = differenceWith(array1, array2, areItemsEqual);
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
*/
export function differenceWith<T>(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[] {
export function differenceWith<T>(
firstArr: readonly T[],
secondArr: readonly T[],
areItemsEqual: (x: T, y: T) => boolean
): T[] {
return firstArr.filter(firstItem => {
return secondArr.every(secondItem => {
return !areItemsEqual(firstItem, secondItem);

View File

@ -20,6 +20,6 @@ export function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) =
if (dropEndIndex === -1) {
return [];
}
return arr.slice(dropEndIndex);
}

View File

@ -19,7 +19,11 @@
* const result = intersectionWith(array1, array2, areItemsEqual);
* // result will be [{ id: 2 }] since this element has a matching id in both arrays.
*/
export function intersectionWith<T>(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[] {
export function intersectionWith<T>(
firstArr: readonly T[],
secondArr: readonly T[],
areItemsEqual: (x: T, y: T) => boolean
): T[] {
return firstArr.filter(firstItem => {
return secondArr.some(secondItem => {
return areItemsEqual(firstItem, secondItem);

View File

@ -19,6 +19,10 @@ import { uniqWith } from './uniqWith';
* const result = unionWith(array1, array2, areItemsEqual);
* // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays
*/
export function unionWith<T>(arr1: readonly T[], arr2: readonly T[], areItemsEqual: (item1: T, item2: T) => boolean): T[] {
export function unionWith<T>(
arr1: readonly T[],
arr2: readonly T[],
areItemsEqual: (item1: T, item2: T) => boolean
): T[] {
return uniqWith(arr1.concat(arr2), areItemsEqual);
}

View File

@ -20,7 +20,11 @@ import { unionWith } from './unionWith';
* xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);
* // Returns [{ id: 1 }, { id: 3 }]
*/
export function xorWith<T>(arr1: readonly T[], arr2: readonly T[], areElementsEqual: (item1: T, item2: T) => boolean): T[] {
export function xorWith<T>(
arr1: readonly T[],
arr2: readonly T[],
areElementsEqual: (item1: T, item2: T) => boolean
): T[] {
const union = unionWith(arr1, arr2, areElementsEqual);
const intersection = intersectionWith(arr1, arr2, areElementsEqual);

View File

@ -22,7 +22,12 @@
export function zip<T>(arr1: readonly T[]): Array<[T]>;
export function zip<T, U>(arr1: readonly T[], arr2: readonly U[]): Array<[T, U]>;
export function zip<T, U, V>(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[]): Array<[T, U, V]>;
export function zip<T, U, V, W>(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): Array<[T, U, V, W]>;
export function zip<T, U, V, W>(
arr1: readonly T[],
arr2: readonly U[],
arr3: readonly V[],
arr4: readonly W[]
): Array<[T, U, V, W]>;
export function zip<T>(...arrs: Array<readonly T[]>): T[][] {
const result: T[][] = [];

View File

@ -28,7 +28,12 @@
*/
export function zipWith<T, R>(arr1: readonly T[], combine: (item: T) => R): R[];
export function zipWith<T, U, R>(arr1: readonly T[], arr2: readonly U[], combine: (item1: T, item2: U) => R): R[];
export function zipWith<T, U, V, R>(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], combine: (item1: T, item2: U, item3: V) => R): R[];
export function zipWith<T, U, V, R>(
arr1: readonly T[],
arr2: readonly U[],
arr3: readonly V[],
combine: (item1: T, item2: U, item3: V) => R
): R[];
export function zipWith<T, U, V, W, R>(
arr1: readonly T[],
arr2: readonly U[],

View File

@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it } from 'vitest';
import { maxBy } from './maxBy';
describe('maxBy', () => {
@ -23,15 +23,13 @@ describe('maxBy', () => {
});
it('if array is single-element, return unique element of array', () => {
const people = [
{ name: 'Mark', age: 25 },
];
const people = [{ name: 'Mark', age: 25 }];
const result = maxBy(people, person => person.age);
expect(result).toEqual({ name: 'Mark', age: 25 });
});
it('if array is empty, return undefined', () => {
type Person = { name: string, age: number };
type Person = { name: string; age: number };
const people: Person[] = [];
const result = maxBy(people, person => person.age);
expect(result).toBeUndefined();

View File

@ -1,39 +1,37 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it } from 'vitest';
import { minBy } from './minBy';
describe('minBy', () => {
it('minBy selects one max value in array', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
{ name: 'Overmars', age: 35 },
];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Nunu', age: 20 });
});
it('minBy selects one max value in array', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
{ name: 'Overmars', age: 35 },
];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Nunu', age: 20 });
});
it('if there are two max values, first one is selected', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
{ name: 'Overmars', age: 20 },
];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Nunu', age: 20 });
});
it('if there are two max values, first one is selected', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
{ name: 'Overmars', age: 20 },
];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Nunu', age: 20 });
});
it('if array is single-element, return unique element of array', () => {
const people = [
{ name: 'Mark', age: 25 },
];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Mark', age: 25 });
});
it('if array is single-element, return unique element of array', () => {
const people = [{ name: 'Mark', age: 25 }];
const result = minBy(people, person => person.age);
expect(result).toEqual({ name: 'Mark', age: 25 });
});
it('if array is empty, return undefined', () => {
type Person = { name: string, age: number };
const people: Person[] = [];
const result = minBy(people, person => person.age);
expect(result).toBeUndefined();
});
});
it('if array is empty, return undefined', () => {
type Person = { name: string; age: number };
const people: Person[] = [];
const result = minBy(people, person => person.age);
expect(result).toBeUndefined();
});
});

View File

@ -9,7 +9,6 @@
* @param selector A function that selects a number from an element.
*/
export function minBy<T>(elements: T[], selector: (element: T) => number): T {
let minElement = elements[0];
let min = Infinity;