diff --git a/docs/ko/reference/array/uniqBy.md b/docs/ko/reference/array/uniqBy.md index c6f72411..e38a6a70 100644 --- a/docs/ko/reference/array/uniqBy.md +++ b/docs/ko/reference/array/uniqBy.md @@ -5,7 +5,7 @@ ## 인터페이스 ```typescript -function uniqBy(arr: T[], mapper: (item: T) => U): T[] +function uniqBy(arr: T[], mapper: (item: T) => U): T[]; ``` ### 파라미터 diff --git a/docs/ko/reference/array/uniqWith.md b/docs/ko/reference/array/uniqWith.md index 2b745dba..0ab6a0ad 100644 --- a/docs/ko/reference/array/uniqWith.md +++ b/docs/ko/reference/array/uniqWith.md @@ -5,7 +5,7 @@ ## 인터페이스 ```typescript -function uniqWith(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[] +function uniqWith(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[]; ``` ### 파라미터 diff --git a/docs/ko/reference/math/maxBy.md b/docs/ko/reference/math/maxBy.md index 862f70cc..112494ed 100644 --- a/docs/ko/reference/math/maxBy.md +++ b/docs/ko/reference/math/maxBy.md @@ -7,7 +7,7 @@ ## 인터페이스 ```typescript -function maxBy(elements: T[], selector: (element: T) => number): T +function maxBy(elements: T[], selector: (element: T) => number): T; ``` ### 파라미터 @@ -22,6 +22,6 @@ function maxBy(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 ``` diff --git a/docs/ko/reference/math/minBy.md b/docs/ko/reference/math/minBy.md index 109f9f7a..3234ac6a 100644 --- a/docs/ko/reference/math/minBy.md +++ b/docs/ko/reference/math/minBy.md @@ -7,7 +7,7 @@ ## 인터페이스 ```typescript -function minBy(elements: T[], selector: (element: T) => number): T +function minBy(elements: T[], selector: (element: T) => number): T; ``` ### 파라미터 @@ -22,6 +22,6 @@ function minBy(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 ``` diff --git a/docs/ko/reference/object/omitBy.md b/docs/ko/reference/object/omitBy.md index b22f6746..16f6c006 100644 --- a/docs/ko/reference/object/omitBy.md +++ b/docs/ko/reference/object/omitBy.md @@ -7,7 +7,10 @@ ## 인터페이스 ```typescript -function omitBy>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial; +function omitBy>( + obj: T, + shouldOmit: (value: T[keyof T], key: keyof T) => boolean +): Partial; ``` ### 파라미터 diff --git a/docs/reference/array/uniqBy.md b/docs/reference/array/uniqBy.md index 2292f4e5..9bb8ac75 100644 --- a/docs/reference/array/uniqBy.md +++ b/docs/reference/array/uniqBy.md @@ -5,7 +5,7 @@ Returns a new array containing only the unique elements from the original array, ## Signature ```typescript -function uniqBy(arr: T[], mapper: (item: T) => U): T[] +function uniqBy(arr: T[], mapper: (item: T) => U): T[]; ``` ### Parameters diff --git a/docs/reference/array/uniqWith.md b/docs/reference/array/uniqWith.md index 8b855e88..0494647d 100644 --- a/docs/reference/array/uniqWith.md +++ b/docs/reference/array/uniqWith.md @@ -5,7 +5,7 @@ Returns a new array containing only the unique elements from the original array, ## Signature ```typescript -function uniqWith(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[] +function uniqWith(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[]; ``` ### Parameters diff --git a/docs/reference/math/maxBy.md b/docs/reference/math/maxBy.md index 18e64114..86563db9 100644 --- a/docs/reference/math/maxBy.md +++ b/docs/reference/math/maxBy.md @@ -7,7 +7,7 @@ If the list is empty, returns `undefined`. ## Signature ```typescript -function maxBy(elements: T[], selector: (element: T) => number): T +function maxBy(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 ``` diff --git a/docs/reference/math/minBy.md b/docs/reference/math/minBy.md index 707c88df..bb209b4d 100644 --- a/docs/reference/math/minBy.md +++ b/docs/reference/math/minBy.md @@ -7,7 +7,7 @@ If the list is empty, returns `undefined`. ## Signature ```typescript -function minBy(elements: T[], selector: (element: T) => number): T +function minBy(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 ``` diff --git a/docs/reference/object/omitBy.md b/docs/reference/object/omitBy.md index 63ebcab6..ff3ee0f3 100644 --- a/docs/reference/object/omitBy.md +++ b/docs/reference/object/omitBy.md @@ -8,7 +8,10 @@ includes only the properties for which the predicate function returns false. ## Signature ```typescript -function omitBy>(obj: T, shouldOmit: (value: T[keyof T], key: keyof T) => boolean): Partial; +function omitBy>( + obj: T, + shouldOmit: (value: T[keyof T], key: keyof T) => boolean +): Partial; ``` ### Parameters diff --git a/src/array/differenceWith.ts b/src/array/differenceWith.ts index bc06cf13..7978338b 100644 --- a/src/array/differenceWith.ts +++ b/src/array/differenceWith.ts @@ -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(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[] { +export function differenceWith( + 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); diff --git a/src/array/dropWhile.ts b/src/array/dropWhile.ts index c6f36685..8713b27c 100644 --- a/src/array/dropWhile.ts +++ b/src/array/dropWhile.ts @@ -20,6 +20,6 @@ export function dropWhile(arr: readonly T[], canContinueDropping: (item: T) = if (dropEndIndex === -1) { return []; } - + return arr.slice(dropEndIndex); } diff --git a/src/array/intersectionWith.ts b/src/array/intersectionWith.ts index 40afa673..5e397286 100644 --- a/src/array/intersectionWith.ts +++ b/src/array/intersectionWith.ts @@ -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(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[] { +export function intersectionWith( + 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); diff --git a/src/array/unionWith.ts b/src/array/unionWith.ts index e34da297..fedad6a9 100644 --- a/src/array/unionWith.ts +++ b/src/array/unionWith.ts @@ -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(arr1: readonly T[], arr2: readonly T[], areItemsEqual: (item1: T, item2: T) => boolean): T[] { +export function unionWith( + arr1: readonly T[], + arr2: readonly T[], + areItemsEqual: (item1: T, item2: T) => boolean +): T[] { return uniqWith(arr1.concat(arr2), areItemsEqual); } diff --git a/src/array/xorWith.ts b/src/array/xorWith.ts index 0a1e3935..3d5053bf 100644 --- a/src/array/xorWith.ts +++ b/src/array/xorWith.ts @@ -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(arr1: readonly T[], arr2: readonly T[], areElementsEqual: (item1: T, item2: T) => boolean): T[] { +export function xorWith( + 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); diff --git a/src/array/zip.ts b/src/array/zip.ts index b5f297c1..6555dbb2 100644 --- a/src/array/zip.ts +++ b/src/array/zip.ts @@ -22,7 +22,12 @@ export function zip(arr1: readonly T[]): Array<[T]>; export function zip(arr1: readonly T[], arr2: readonly U[]): Array<[T, U]>; export function zip(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[]): Array<[T, U, V]>; -export function zip(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], arr4: readonly W[]): Array<[T, U, V, W]>; +export function zip( + arr1: readonly T[], + arr2: readonly U[], + arr3: readonly V[], + arr4: readonly W[] +): Array<[T, U, V, W]>; export function zip(...arrs: Array): T[][] { const result: T[][] = []; diff --git a/src/array/zipWith.ts b/src/array/zipWith.ts index 83a09a91..bdf0ab8f 100644 --- a/src/array/zipWith.ts +++ b/src/array/zipWith.ts @@ -28,7 +28,12 @@ */ export function zipWith(arr1: readonly T[], combine: (item: T) => R): R[]; export function zipWith(arr1: readonly T[], arr2: readonly U[], combine: (item1: T, item2: U) => R): R[]; -export function zipWith(arr1: readonly T[], arr2: readonly U[], arr3: readonly V[], combine: (item1: T, item2: U, item3: V) => R): R[]; +export function zipWith( + arr1: readonly T[], + arr2: readonly U[], + arr3: readonly V[], + combine: (item1: T, item2: U, item3: V) => R +): R[]; export function zipWith( arr1: readonly T[], arr2: readonly U[], diff --git a/src/math/maxBy.spec.ts b/src/math/maxBy.spec.ts index 514dc142..a06a52e1 100644 --- a/src/math/maxBy.spec.ts +++ b/src/math/maxBy.spec.ts @@ -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(); diff --git a/src/math/minBy.spec.ts b/src/math/minBy.spec.ts index 696d8422..eba9c55a 100644 --- a/src/math/minBy.spec.ts +++ b/src/math/minBy.spec.ts @@ -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(); - }); -}); \ No newline at end of file + 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(); + }); +}); diff --git a/src/math/minBy.ts b/src/math/minBy.ts index 910a9229..ce2aba8c 100644 --- a/src/math/minBy.ts +++ b/src/math/minBy.ts @@ -9,7 +9,6 @@ * @param selector A function that selects a number from an element. */ export function minBy(elements: T[], selector: (element: T) => number): T { - let minElement = elements[0]; let min = Infinity;