Array.prototype.flatMapadvancedconst strs = ['hello', '', 'world', '']
strs.flatMap(s => s ? [s.trim()] : [])
// β ['hello', 'world']Use flatMap() to simultaneously trim, filter out empty strings, and flatten results.
flatMap() can both transform and filter in one pass. Trimming strings and removing empty ones is a clean use case.
Challenge: Implement compactMap(arr) that trims each string and removes empty strings using flatMap.
compactMap([' hello ', '', ' world ', ' ']) // β ['hello', 'world']
compactMap(['', ' ']) // β []