My current challenge involves sorting an array of data multiple times for different purposes. While I could choose to save the sorted data on the back end, I prefer handling it this way.
However, I have encountered a problem where only one sort operation seems to be effective, as shown in the following example: this is the component
export class xService {
comp$: Observable<any[]> | undefined;
c1 = new Array();
cp1 = new Array();
at_b3 = new Array();
at_b = new Array();
at_b2 = new Array();
constructor(public a_s: AServ, private db: AngularFireDatabase) {
this.comp$ = this.a_s.xc$.pipe(switchMap((x) => {
return this.db.list('people/'+x).valueChanges();
}));
this.comp$.subscribe({next: (value) => {
this.c1 = value[0];
this.cp1 = value[0].users;
this.at_b3 = value[0].users;
this.a_s.statsa.push(value[0].users);
this.at_b = this.cp1.sort((a: any, b: any) => Number(a.stats[0].day_off) - Number(b.stats[0].day_off)).reverse();
this.at_b2 = this.cp1.sort((a: any, b: any) => Number(a.stats[0].places_went) - Number(b.stats[0].places_went)).reverse();
console.log(this.at_b)
console.log(this.at_b2)
}
});
}
}
Specifically, I am facing issues with the following code snippet:
this.at_b = this.cp1.sort((a: any, b: any) => Number(a.stats[0].day_off) - Number(b.stats[0].day_off)).reverse();
this.at_b2 = this.cp1.sort((a: any, b: any) => Number(a.stats[0].places_went) - Number(b.stats[0].places_went)).reverse();
Despite my efforts, when attempting to render or utilize console logs, I am unable to access two distinct arrays; instead, I seem to retrieve the same array repeatedly.