I am looking to update the filterOutEmails function in the following class to use array.some instead of the current code.
export class UsertableComponent {
dataSource: MatTableDataSource<TrialUser>
createTableFromServer = (data: TrialUsers[], emailDomains:string) => {
this.dataSource = new MatTableDataSource(data);
this.dataSource.filterPredicate = this.filterOutEmails;
}
filterOutEmails = (row: TrialUser, emailDomains: string): boolean => {
const listofFilters = emailDomains.split(',');
for (let i = 0; i < listofFilters.length; i++){
if (row.email.toLowerCase().includes(listofFilters[i].trim())){
return true;
}
}
return false;
}
}
I attempted to make the change using a separate determineIfRowShouldBeShown method but ran into issues with "this". I also tried using an arrow function inline, which worked. However, I prefer to keep the function definition separate.
private determineIfRowShouldBeShown(this: TrialUser, domain: string): boolean {
const row: TrialUser = this;
return !row.email.toLowerCase().includes(domain.trim());
}
private filterOutEmails= (row: TrialUser, emailDomains: string): boolean {
const listofFilters = emailDomains.split(',');
return listofFilters.some(this.determineIfRowShouldBeShown, row) ;
}
}