Uber | Phone Screen | Senior Front End Engineer
Anonymous User
4945

The interviewer was very friendly, we discussed each other's background for the first 5 minutes and then got right into it. Below is the question that I was asked.

By far one of the harder questions I've been asked in an interview, I completley bombed it. I got stuck several times and the interviewer gave me some hints. The inteviewer mentioned that getNameById is just an example function, the solution should be abstracted enough so that any function can be used in it's place. He also said that he doesn't expect candidates to get to a working solution by the end of the session and that he was more interested in their thought process.

We were given this prompt in code signal and expected to come to a solution using Javascript.

// 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.

// Inputs
// inputs: An array of inputs.
// limit: The maximum number of operations at any one time.
// iterateeFn: The async function that should be called with each input to generate the corresponding output. It will have two arguments:
//      input: The input being processed.
//      callback: A function that will be called when the input is finished processing. It will be provided one argument, the processed output.
// callback: A function that should be called with the array of outputs once all the inputs have been processed.

function getNameById(id, callback) {
  // simulating async request
  const randomRequestTime = Math.floor(Math.random() * 100) + 200;

  setTimeout(() => {
    callback("User" + id);
  }, randomRequestTime);
}

function mapLimit(inputs, limit, iterateeFn, callback) {
  // implement here

  //




}
//example: 
mapLimit([1, 2, 3, 4, 5], 2, getNameById, (allResults) => {
  console.log("output", allResults); // ["User1", "User2", "User3", "User4", "User5"]
});
Comments (18)