Exercise 10: Batch Fetch Multiple URLs

Problem Statement

Function `batchFetch(urls, options)` banao jo multiple URLs ko parallel me fetch kare. Example: batchFetch(["url1", "url2"], {}) => [response1, response2]

Sample Output:

await batchFetch(["url1", "url2"], {}) => [response1, response2]
// Fetches all URLs in parallel

Solution

const batchFetch = async (urls, options = {}) => {
  return Promise.all(urls.map(url => fetch(url, options)));
};

Explanation

Overall Goal:

  • Multiple URLs ko parallel me fetch karna.

Real world:

  • Multiple APIs: parallel requests.
  • Data loading: batch requests.