Skip to content Skip to sidebar Skip to footer

How Can I Show Only 1 Record Which Has A Least Score Among All?

I wanted to show only 1 record among the DL list which has a minimum score from all the DLs. Currently it's displaying all the records. In the example on stackblitz you can see for

Solution 1:

You can find working example here in this stackbliz link

I have created one pipe to filter out data...

custom-pipe is

import { Pipe, PipeTransform } from"@angular/core";

@Pipe({
  name: "filterDL"
})

exportclassFilterDLPipeimplementsPipeTransform {
     transform(value: any, args?: any): any {
        console.log("filter pipe ", value);
        let filter = value.filter(item =>Number(item.co_score));
        let leastScrore = Math.min(...filter.map(item => item.co_score));
        let findIndex = filter.filter(item => item.co_score === leastScrore);
        console.log("findex", findIndex);
        console.log(leastScrore);
      return findIndex;
    }
}

then apply this pipe to your DL array to filter out array.

<ul><li *ngFor="let assignee of user.assigned_to | filterDL">
                {{assignee.dl}} {{assignee.co_score}}
     </li></ul>

and you will get your desired minimum score outpur in DL.

Solution 2:

One thing you could try it to find the lowest score in one step and return the index, and then grab the element at that index from the assigned_to array in the next step. If you want to go deeper, you could look at the filter and find methods on Array

Post a Comment for "How Can I Show Only 1 Record Which Has A Least Score Among All?"