Challenge - 5 Problems
Transform Stream Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Node.js transform stream?
Consider this transform stream that converts input text to uppercase. What will be printed to the console when piping 'hello world' through it?
Node.js
import { Transform } from 'stream'; const upperCaseTransform = new Transform({ transform(chunk, encoding, callback) { this.push(chunk.toString().toUpperCase()); callback(); } }); process.stdin.pipe(upperCaseTransform).pipe(process.stdout); // Input: 'hello world' (typed by user)
Attempts:
2 left
💡 Hint
Think about what the transform function does to each chunk of data.
✗ Incorrect
The transform stream converts each chunk to uppercase before pushing it forward. So the output will be the uppercase version of the input.
📝 Syntax
intermediate2:00remaining
Which option correctly implements a transform stream that reverses input strings?
You want to create a transform stream that reverses each chunk of text. Which code snippet is syntactically correct and works as intended?
Attempts:
2 left
💡 Hint
Remember the transform method signature and how to push transformed data.
✗ Incorrect
Options A and C correctly implement the reversal. A uses this.push(reversed) then callback(). C uses callback(null, reversed), which is equivalent and internally pushes the data. B misses the callback parameter/call (stream hangs) and reverse() on string (invalid). D reverses Buffer directly (no reverse() method, error).
🔧 Debug
advanced2:00remaining
Why does this transform stream cause a runtime error?
Examine this transform stream code. Why does it throw an error when processing input?
Node.js
import { Transform } from 'stream'; const faultyTransform = new Transform({ transform(chunk, encoding, callback) { const data = chunk.toString().toUpperCase(); this.push(data); callback(); } });
Attempts:
2 left
💡 Hint
Check the type of chunk and what methods it supports.
✗ Incorrect
chunk is a Buffer object, which does not have a toUpperCase method. You must convert chunk to string first.
❓ state_output
advanced2:00remaining
What is the final output of this transform stream pipeline?
This pipeline reads input, doubles numbers in text, and outputs the result. What will be printed if input is '1 2 3'?
Node.js
import { Transform } from 'stream'; import { Readable } from 'stream'; const doubleNumbers = new Transform({ transform(chunk, encoding, callback) { const input = chunk.toString(); const doubled = input.split(' ').map(n => Number(n) * 2).join(' '); this.push(doubled); callback(); } }); const inputStream = Readable.from(['1 2 3']); inputStream.pipe(doubleNumbers).pipe(process.stdout);
Attempts:
2 left
💡 Hint
Look at how numbers are processed and doubled.
✗ Incorrect
The transform splits the string by spaces, converts each to a number, doubles it, then joins back. So '1 2 3' becomes '2 4 6'.
🧠 Conceptual
expert2:00remaining
Which statement about Node.js transform streams is TRUE?
Select the correct statement about how transform streams work in Node.js.
Attempts:
2 left
💡 Hint
Think about the transform method contract and stream behavior.
✗ Incorrect
Transform streams modify data chunks and must call callback() to signal completion. They can change chunk size and are both readable and writable.