Jump to content

andy246

Members
  • Posts

    1
  • Joined

  • Last visited

andy246's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. This is a question I got asked in an interview. I know the array would just return zeros since this is asynchronous, but why does this happen, and how can you fix it so that the results array inserts the appropriate data? Question: Suppose findData is a function that takes a query object and returns a promise for the result of the query. Suppose also that someRandomArrayOfQueries is an array of query objects. Explain what would be printed by the following code and why: function runMultipleQueries(queries) { var results = []; queries.forEach(doQuery); return results; function doQuery(query) { findData(query) .then(results.push.bind(results)); } }function log(value) { console.log(value);}runMultipleQueries(someRandomArrayOfQueries).forEach(log);
×
×
  • Create New...