Pipeline Processor - Problem
Create a higher-order function called pipeline that takes multiple transformation functions as arguments and returns a new function. This returned function should apply all the transformations in sequence to an input value.
Function Signature:
pipeline(transform1, transform2, ..., transformN) → returns a function
The returned function should take an input and pass it through each transformation function in order, where the output of one function becomes the input of the next.
Example Usage:
const processor = pipeline(trim, lowercase, removeSpaces);const result = processor(" Hello World "); → "helloworld"
Input & Output
Example 1 — Basic Text Processing
$
Input:
input = " Hello World ", transforms = ["trim", "lowercase", "removeSpaces"]
›
Output:
"helloworld"
💡 Note:
Step by step: trim(" Hello World ") → "Hello World" → lowercase("Hello World") → "hello world" → removeSpaces("hello world") → "helloworld"
Example 2 — Uppercase and Reverse
$
Input:
input = "hello", transforms = ["uppercase", "reverse"]
›
Output:
"OLLEH"
💡 Note:
First uppercase("hello") → "HELLO", then reverse("HELLO") → "OLLEH"
Example 3 — Single Transform
$
Input:
input = " spaces ", transforms = ["trim"]
›
Output:
"spaces"
💡 Note:
Only one transformation applied: trim removes leading and trailing whitespace
Constraints
- 1 ≤ input.length ≤ 1000
- 1 ≤ transforms.length ≤ 10
- Available transforms: trim, lowercase, uppercase, removeSpaces, reverse
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code