max

The max() operator finds the largest value. This comes in two flavors: we either just call the max() operator with no arguments, or we give it a compare function. The compare function then decides whether something is larger than, smaller than, or equal to an emitted value. Let's have a look at the two different versions:

// mathematical/max.jslet streamWithNumbers$ = Rx.Observable  .of(1,2,3,4)  .max();// 4streamWithNumbers$.subscribe(data => console.log(data)); function comparePeople(firstPerson, secondPerson) {  if (firstPerson.age > secondPerson.age) {    return 1;   } else if (firstPerson.age < secondPerson.age) {    return -1;  }   return 0;}let streamOfObjects$ = Rx.Observable  .of({    name : "Yoda",    age: 999  }, {    name : "Chris",    age: 38  }) ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.