Problem, as an interviewer would state it:
"Write waterfall(tasks, initial) — run an array of async functions one after another, each receiving the PREVIOUS one's result as its own input, returning the final result."
Examples:
await waterfall([addOne, double, toString], 5);
// addOne(5)=6 -> double(6)=12 -> toString(12)="result: 12"
Clarifying questions expected:
- Does this genuinely need to run sequentially, or would running everything in parallel and just chaining the DATA dependency be acceptable?
- What happens if one task in the middle rejects — does the whole waterfall stop?
- Is the very first task's input always the same as the overall
initialvalue passed in?
Code / implementation expected: Yes — real, direct proof via a logged execution order that this is genuinely sequential, not just producing the correct final chained result by coincidence.