Node.js Implement the getInParallel function that should be used to invoke multiple API calls in parallel. The function accepts an array of functions that return a Promise. The function should return a Promise which should resolve to an array of results from the apiCalls argument. For example, calling the following code should print "[ 'First API call!', 'Second API call!' ]": let promise = getInParallel([() => Promise.resolve("First API call!"), () => Promise.resolve("Second API call!")]); if(promise) { promise.then((result) => console.log(result)).catch((err) => console.log(err)); } Submit & Next Remaining time: 22 min
// function that: Node.js Implement the getInParallel function that should be used to invoke multiple API calls in parallel. The function accepts an array of functions that return a Promise. The function should return a Promise which should resolve to an array of results from the apiCalls argument. // For example, calling the following code should print "[ 'First API call!', 'Second API call!' ]": // let promise = getInParallel([() => Promise.resolve("First API call!"), () => Promise.resolve("Second API call!")]); // if(promise) { // promise.then((result) => console.log(result)).catch((err) => console.log(err)); // } function getInParallel(apiCalls) { let returnValue = Promise.resolve(); apiCalls.forEach((apiCall) => { returnValue = returnValue.then(apiCall); }); return returnValue; } let promise = getInParallel([() => Promise.resolve("First API call!"), () => Promise.resolve("Second