How to Group Data and Find Maximums by Group in Angular using RxJS
How to Group Data and Find Maximums by Group in Angular using RxJS Have you ever faced an interview question where you need to take a flat list of employee records and group them by department to find the highest earner? While it sounds straightforward, doing this reactively with RxJS can quickly lead to tricky bugs if operators are chained out of order. In this post, we will look at a common broken snippet, dissect why it fails, and implement two clean ways to solve it. The Problem Scenario Imagine you have the following flat dataset inside an Angular component: employees = [ { id : 0 , name : "Mani" , dept : "IT" , salary : 12000 }, { id : 1 , name : "Lava" , dept : "IT" , salary : 1200 }, { id : 2 , name : "Nila" , dept : "Medical" , salary : 12000 }, { id : 3 , name : "Test" , dept : "IT" , salary : 12000 }, { id : 4 , name : "JHi" , dept : "Medical" , salary : 12000 }, {...