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,如若转载,请注明出处:https://www.web176.com/rxjs/1811.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年2月8日 下午2:57
下一篇 2021年2月8日 下午3:02

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注