diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/article.md b/1-js/12-generators-iterators/2-async-iterators-generators/article.md index d4e9f78616..8704d2986f 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/article.md +++ b/1-js/12-generators-iterators/2-async-iterators-generators/article.md @@ -341,15 +341,12 @@ async function* fetchCommits(repo) { headers: {'User-Agent': 'Our script'}, // github needs any user-agent header }); - const body = await response.json(); // (2) response is JSON (array of commits) + const commits = await response.json(); // (2) response is JSON (array of commits) // (3) the URL of the next page is in the headers, extract it - let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/); - nextPage = nextPage?.[1]; + url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1]; - url = nextPage; - - for(let commit of body) { // (4) yield commits one by one, until the page ends + for (const commit of commits) { // (4) yield commits one by one, until the page ends yield commit; } } diff --git a/1-js/12-generators-iterators/2-async-iterators-generators/head.html b/1-js/12-generators-iterators/2-async-iterators-generators/head.html index 03f21e2bd8..2993ffb019 100644 --- a/1-js/12-generators-iterators/2-async-iterators-generators/head.html +++ b/1-js/12-generators-iterators/2-async-iterators-generators/head.html @@ -7,16 +7,13 @@ headers: {'User-Agent': 'Our script'}, // github requires user-agent header }); - const body = await response.json(); // parses response as JSON (array of commits) + const commits = await response.json(); // parses response as JSON (array of commits) // the URL of the next page is in the headers, extract it - let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/); - nextPage = nextPage?.[1]; - - url = nextPage; + url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1]; // yield commits one by one, when they finish - fetch a new page url - for(let commit of body) { + for (const commit of commits) { yield commit; } }