Uber | Phone Screen | Run async graph

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-03-23Added By Anonymous
Source: Link

Company: Uber
Role: front-end role
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

Interviewed for a front-end role. Was asked this question and I\'m still stumped. Since every task calls a done method, I thought of it as resolve in Promise, but didn\'t make much progress

function taskA(done) {
  console.log(\"Task A Completed\");
  done();
}
function taskB(done) {
  setTimeout(function () {
    console.log(\"Task B Completed\");
    done();
  }, 2000);
}
function taskC(done) {
  setTimeout(function () {
    console.log(\"Task C Completed\");
    done();
  }, 200);
}
function taskD(done) {
  console.log(\"Task D Completed\");
  done();
}
function taskE(done) {
  console.log(\"Task E Completed\");
  done();
}

const asyncGraph = {
  a: {
    task: taskA,
  },
  b: {
    task: taskB,
  },
  c: {
    task: taskC,
  },
  d: {
    dependency: [\"a\", \"b\"],
    task: taskD,
  },
  e: {
    dependency: [\"c\", \"d\"],
    task: taskE,
  },
};

function runAsyncGraph(graph, callback) {
  // implement

}

Comments