Bird
0
0

You want to create a custom pipe that converts a comma-separated string into an array of trimmed strings. Which implementation correctly achieves this?

hard📝 component behavior Q8 of 15
NestJS - Pipes

You want to create a custom pipe that converts a comma-separated string into an array of trimmed strings. Which implementation correctly achieves this?

Atransform(value: string) { return value.split(','); }
Btransform(value: string) { return value.trim().split(','); }
Ctransform(value: string) { return value.split(',').map(s => s.trim()); }
Dtransform(value: string) { return value.toUpperCase().split(','); }
Step-by-Step Solution
Solution:
  1. Step 1: Split string by commas

    Use split(',') to divide the string into parts.
  2. Step 2: Trim each part

    Use map with trim() to remove spaces from each substring.
  3. Final Answer:

    transform(value: string) { return value.split(',').map(s => s.trim()); } -> Option C
  4. Quick Check:

    Split then trim each element for clean array [OK]
Quick Trick: Split first, then trim each element for clean array [OK]
Common Mistakes:
  • Trimming before splitting
  • Not trimming elements
  • Changing case unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes