Rxjs-mathematical-operator-max

提供:Dev Guides
移動先:案内検索

RxJS-数学演算子最大

max()メソッドは、すべての値を持つオブザーバブルを取り込み、最大値を持つオブザーバブルを返します。 これは、オプションとして、比較関数を引数として受け取ります。

構文

max(comparer_func?: number): Observable

パラメーター

*_comparer_func_* -(オプション)。 ソースオブザーバブルからの最大値と見なされる値をフィルタリングする関数。 指定しない場合、デフォルトの機能が考慮されます。

戻り値

戻り値は、最大値を持つオブザーバブルです。

例1

次の例は、最大値である-

import { of } from 'rxjs';
import { max } from 'rxjs/operators';

let all_nums = of(1, 6, 15, 10, 58, 20, 40);
let final_val = all_nums.pipe(max());
final_val.subscribe(x => console.log("The Max value is "+x));

出力

The Max value is 58

例2

次の例は、比較関数の最大値です-

import { from } from 'rxjs';
import { max } from 'rxjs/operators';

let list1 = [1, 6, 15, 10, 58, 2, 40];
let final_val = from(list1).pipe(max((a,b)=>a-b));
final_val.subscribe(x => console.log("The Max value is "+x));

配列を使用しており、配列内の値はmax関数で指定された関数を使用して比較され、配列からの最大値が返されます。

出力

The Max value is 58