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


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


1function taskA(done) { 2 console.log(\"Task A Completed\"); 3 done(); 4} 5function taskB(done) { 6 setTimeout(function () { 7 console.log(\"Task B Completed\"); 8 done(); 9 }, 2000); 10} 11function taskC(done) { 12 setTimeout(function () { 13 console.log(\"Task C Completed\"); 14 done(); 15 }, 200); 16} 17function taskD(done) { 18 console.log(\"Task D Completed\"); 19 done(); 20} 21function taskE(done) { 22 console.log(\"Task E Completed\"); 23 done(); 24} 25 26const asyncGraph = { 27 a: { 28 task: taskA, 29 }, 30 b: { 31 task: taskB, 32 }, 33 c: { 34 task: taskC, 35 }, 36 d: { 37 dependency: [\"a\", \"b\"], 38 task: taskD, 39 }, 40 e: { 41 dependency: [\"c\", \"d\"], 42 task: taskE, 43 }, 44}; 45 46function runAsyncGraph(graph, callback) { 47 // implement 48 49} 50
Comments