I read about ternary operators but both the filter data and sort data is still kind of confusing. I might be understanding it wrong but it seems to be a sort of IF.
This is from the ZORRO framework. Section - Filter and Sorter
https://ng.ant.design/components/table/en#components-table-demo-virtual
search(): void {
/** filter data **/
const filterFunc = (item: { name: string; age: number; address: string }) =>
(this.searchAddress ? item.address.indexOf(this.searchAddress) !== -1 : true) &&
(this.listOfSearchName.length ? this.listOfSearchName.some(name => item.name.indexOf(name) !== -1) : true);
const data = this.listOfData.filter(item => filterFunc(item));
console.log(data);
/** sort data **/
if (this.sortName && this.sortValue) {
this.listOfDisplayData = data.sort((a, b) =>
this.sortValue === 'ascend'
? a[this.sortName!] > b[this.sortName!]
? 1
: -1
: b[this.sortName!] > a[this.sortName!]
? 1
: -1
);
} else {
this.listOfDisplayData = data;
}
}