Reply
Sat 27 Jun, 2015 08:32 am
Hi, I recently got an interview and I need to solve this problem. I can't figure it out though.... can anybody help?
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);