Skip to content

Instantly share code, notes, and snippets.

@finki001
Last active November 5, 2019 10:28
Show Gist options
  • Save finki001/0f485c1fb74f94c142536090725654b3 to your computer and use it in GitHub Desktop.
Save finki001/0f485c1fb74f94c142536090725654b3 to your computer and use it in GitHub Desktop.
@Pipe({
name: "sortDescending"
})
export class SortDescendingPipe implements PipeTransform {
transform(list: any[], ...args: any[]): any[] {
return list.slice().sort((elem1, elem2) => elem2.rollNo - elem1.rollNo);
}
}
// use it in your template like this:
{{ todo | sortDescending }} to display it or like <div *ngFor="let singleTodo of todo | sortDescending">…</div> to iterate over the descending array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment