I recently developed a TypeScript code snippet that searches for objects in a list by their name and surname, not strictly equal:
list = list.filter(
x => (x.surname + ' ' + x.name)
.trim()
.toLowerCase()
.search(filter.toLowerCase()) >= 0);
For instance, if I search for "al" and want to find "Alex", the code will display "Alex" as a valid result.
However, when I migrated this code to a JavaScript environment, it encountered errors related to the search function and trim method.
Is there a more efficient way to achieve this functionality without resorting to nested loops?