https://i.sstatic.net/qHkff.png
I am currently developing an angular application that includes:
- a group of filters
- and data records displayed in a table
The columns in the table correspond to the filters, where each filter contains unique values from its corresponding column as options.
In some cases, a column can have more than one value associated with it, meaning multiple options from the corresponding filter.
Whenever a user selects an option from a filter, the table is filtered accordingly, displaying only the records that match the user's selection.
After filtering the records, I need to extract unique values for each filter based on the filtered dataset and find distinct options for each key.
The keys of the Filter objects align with the columns of the Record objects. My goal is to iterate over both the lists of records and filters to identify the unique values for each column key.
Outlined below is the logic I'm using to derive unique filter options from my data:
export function filterOptionsService(records: Record[], filters: RecordFilter[]): RecordFilter[] {
// Implementation logic here...
}
The part of my code that takes the longest time involves extracting filter options for a specific key from a dataset. It currently runs for 7 seconds when processing 8k records.
const filterOptions = records.reduce((uniqueList, record) =>
uniqueList.concat(record[filter.key]), []);
I've encountered performance issues with this implementation and would appreciate any insights on areas where optimization is needed.
If you'd like to view a sample TypeScript playground code, visit the following link: Click here to access the TypeScript Playground.