I had a coding challenge where this just stumped me:
function runMultipleQueries(queries) {
var results = [];
queries.forEach(doQuery);
return results;
function doQuery(query) {
getData(query)
.then(results.push.bind(results));
}
}
function log(value) {
console.log(value);
}
runMultipleQueries(someArrayOfQueries).forEach(log);
Edit: Assume these functions are all defined elsewhere in script.
What would be the hypothetical output of this codeblock? I'm getting stumped on when the promise gets returned, and what is printed in the meantime? I was thinking I would see an array of UNDEFINED, but now im not sure!