Categories: RxJS教程

RxJS:数学运算符Min

min()方法将使用所有值的可观察值,并返回具有最小值的可观察值。它以比较函数作为参数,这是可选的。

语法

min(comparer_func?: number): Observable

参量

comparer_func-(可选)。可以从源观察到的最小值中过滤要考虑的值的函数。如果未提供,则考虑默认函数。

返回值

返回值是一个具有最小值的可观察值。

例子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
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts