Rx.Observable.prototype.min([comparer])

Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.

Arguments

  1. [comparer] (Function): Comparer used to compare elements.

Returns

(Observable): An observable sequence containing a single element with the minimum element in the source sequence.

Example

/* Without comparer */
var source = Rx.Observable.from([1,3,5,7,9,2,4,6,8])
    .min();

var subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 1
// => Completed

/* With a comparer */
function comparer (x, y) {
    if (x > y) {
        return 1;
    } else if (x < y) {
        return -1;
    }
    return 0;
}

var source = Rx.Observable.from([1,3,5,7,9,2,4,6,8])
    .min(comparer);

var subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 1
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests:

results matching ""

    No results matching ""