docs: Add detail examples to docs in maxBy, minBy (#554)
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run

* docs: Add detail examples to docs in maxBy, minBy

* docs: Add examples for maxBy and minBy functions to en, ja, zh_hans docs
This commit is contained in:
Goblin (Kim Woo Seok) 2024-09-23 18:53:02 +09:00 committed by GitHub
parent 1ba076a2ac
commit 53703f4abb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 112 additions and 0 deletions

View File

@ -24,4 +24,12 @@ function maxBy<T>(items: T[], getValue: (element: T) => number): T;
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 戻り値: { a: 3 }
maxBy([], x => x.a); // 戻り値: undefined
maxBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // 戻り値: { name: 'john', age: 30 }
```

View File

@ -22,4 +22,12 @@ function minBy<T>(items: T[], getValue: (element: T) => number): T;
```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 戻り値: { a: 1 }
minBy([], x => x.a); // 戻り値: undefined
minBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // 戻り値: { name: 'joe', age: 26 }
```

View File

@ -25,4 +25,12 @@ function maxBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
maxBy([], x => x.a); // Returns: undefined
maxBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // Returns: { name: 'john', age: 30 }
```

View File

@ -23,4 +23,12 @@ function minBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
minBy([], x => x.a); // Returns: undefined
minBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // Returns: { name: 'joe', age: 26 }
```

View File

@ -23,4 +23,12 @@ function maxBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
maxBy([], x => x.a); // Returns: undefined
maxBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // Returns: { name: 'john', age: 30 }
```

View File

@ -23,4 +23,12 @@ function minBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
minBy([], x => x.a); // Returns: undefined
minBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // Returns: { name: 'joe', age: 26 }
```

View File

@ -25,4 +25,12 @@ function maxBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 返回: { a: 3 }
maxBy([], x => x.a); // 返回: undefined
maxBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // 返回: { name: 'john', age: 30 }
```

View File

@ -25,4 +25,12 @@ function minBy<T>(items: T[], getValue: (element: T) => number): T | undefined;
```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // 返回: { a: 1 }
minBy([], x => x.a); // 返回: undefined
minBy(
[
{ name: 'john', age: 30 },
{ name: 'jane', age: 28 },
{ name: 'joe', age: 26 },
],
x => x.age
); // 返回: { name: 'joe', age: 26 }
```

View File

@ -9,6 +9,14 @@
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
*/
export function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
/**
@ -22,6 +30,14 @@ export function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
*/
export function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
/**
@ -35,6 +51,14 @@ export function maxBy<T>(items: readonly T[], getValue: (element: T) => number):
* @example
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
* maxBy([], x => x.a); // Returns: undefined
* maxBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'john', age: 30 }
*/
export function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T {
let maxElement = items[0];

View File

@ -9,6 +9,14 @@
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
*/
export function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
/**
@ -22,6 +30,14 @@ export function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
*/
export function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
/**
@ -35,6 +51,14 @@ export function minBy<T>(items: readonly T[], getValue: (element: T) => number):
* @example
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
* minBy([], x => x.a); // Returns: undefined
* minBy(
* [
* { name: 'john', age: 30 },
* { name: 'jane', age: 28 },
* { name: 'joe', age: 26 },
* ],
* x => x.age
* ); // Returns: { name: 'joe', age: 26 }
*/
export function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined {
let minElement = items[0];