HardPro challengePythonJavaScriptTypeScript
Stream Pipeline
BackendStreamsFunctional
Implement pipeline(source, transforms) where:
sourceis an array of values.- Each transform is an expression string like
'x => x * 2'or
'x => x > 4 ? x : undefined'. Compile each via
new Function('return (' + expr + ');')().
For each value, run all transforms in order. If a transform returnsundefined, drop the value. Return the array of surviving values.
solve([1, 2, 3, 4], ['x => x * 2', 'x => x > 4 ? x : undefined']) → [6, 8].
Sample tests
Test #1No transforms passes through
Input: [[1,2,3],[]]
Output: [1,2,3]
Test #2Empty source
Input: [[],["x => x"]]
Output: []
Test #3Filter only
Input: [[1,2,3,4,5],["x => x % 2 === 0 ? x : undefined"]]
Output: [2,4]
Test #4Chained
Input: [[10],["x => x + 1","x => x * 2"]]
Output: [22]
Test #5Map then filter
Input: [[1,2,3,4],["x => x * 2","x => x > 4 ? x : undefined"]]
Output: [6,8]