Run Async Tasks in Order

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write runInSequence(tasks), where tasks is an array of functions that each take no arguments and return a promise. Call the first task, wait for its promise to resolve, then call the next, and so on, so no two tasks run at once. Return a promise of an array of their results, in order. If a task's promise rejects, reject with that reason and don't call the tasks after it. An empty array resolves to an empty array.

Your code must pass

  • Resolves with every result, in order
  • Starts each task only after the one before has finished
  • Stops at the first rejection
  • Resolves an empty array to an empty array