min()方法将使用所有值的可观察值,并返回具有最小值的可观察值。它以比较函数作为参数,这是可选的。
min(comparer_func?: number): Observable
comparer_func-(可选)。可以从源观察到的最小值中过滤要考虑的值的函数。如果未提供,则考虑默认函数。
返回值是一个具有最小值的可观察值。
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
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