Uber FrontEnd Phone Screen

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-05-26Added By Anonymous
Source: Link

Company: Uber

Interview Stage: Phone Screen


Original Post Content:


I was having a hard time coming up with a solution for this question. I couldn't come up with an answer, thought of sharing with you folks, could be helpful for someone else applying! Also, if someone could help solve this problem will be helpful to understand

1// Implement mapLimit, which is a utility function that produces a list of outputs by mapping each input through an asynchronous iteratee function. The Provided limit dictates how many operations can occur at once. 2// Inputs 3// inputs: An array of inputs. 4// limit: The maximum number of operations at any one time. 5// iterateeFn: The async function that should be called with each input to generate the corresponding output. It will have two arguments: 6// input: The input being processed. 7// callback: A function that will be called when the input is finished processing. It will be provided one argument, the processed output. 8// callback: A function that should be called with the array of outputs once all the inputs have been processed. 9 10function getNameById(id, callback) { 11 // simulating async request 12 const randomRequestTime = Math.floor(Math.random() * 100) + 200; 13 14 setTimeout(() => { 15 callback("User" + id) 16 }, randomRequestTime); 17} 18 19function mapLimit(inputs, limit, iterateeFn, callback) { 20 // implement here 21} 22 23mapLimit([1,2,3,4,5], 2, getNameById, (allResults) => { 24 console.log('output:', allResults) // ["User1", "User2", "User3", "User4", "User5"] 25})
Comments