RxJS - 數學運算子 Min



min() 方法將接收帶有所有值的 Observable,並返回一個帶有最小值的可觀測物件。它把一個比較函式作為引數,該函式是可選的。

語法

min(comparer_func?: number): Observable

引數

comparer_func - (可選)。一個函式,它將從源 Observable 中篩選要考慮的用於獲取最小值的那些值。如果沒有提供,則會考慮預設函式。

返回值

返回值是一個 Observable,它將具有最小值。

示例 1

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

let list1 = [1, 6, 15, 10, 58, 2, 40];
let final_val = of(1, 6, 15, 10, 58, 2, 40).pipe(min());

final_val.subscribe(x => console.log("The Min value is "+x));

輸出

The Min value is 1

示例 2

import { of ,from} from 'rxjs';
import { min } from 'rxjs/operators';

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

輸出

The Min value is 1
廣告
© . All rights reserved.