From 753123e7a7521cf4bbf7ce4f1b6523965076f4f0 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Thu, 8 Aug 2024 13:50:54 +0200 Subject: [PATCH] Directly use find in articleTmpl --- .../dragon-trainer-monthly-authors/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js-essentials/dragon-trainer-monthly-authors/script.js b/js-essentials/dragon-trainer-monthly-authors/script.js index 289a9b5..efe1f15 100644 --- a/js-essentials/dragon-trainer-monthly-authors/script.js +++ b/js-essentials/dragon-trainer-monthly-authors/script.js @@ -1,9 +1,9 @@ let app = document.querySelector('#app'); -let endpoints = { - articles: 'https://vanillajsacademy.com/api/dragons.json', - authors: 'https://vanillajsacademy.com/api/dragons-authors.json' -} +let endpoints = [ + 'https://vanillajsacademy.com/api/dragons.json', + 'https://vanillajsacademy.com/api/dragons-authors.json' +]; let articleTmpl = function (item, authors) { return ` @@ -12,7 +12,7 @@ let articleTmpl = function (item, authors) { ${item.pubdate}
by ${item.author} -

${function () { return authors.find(function (author) { return author.author === item.author} )}().bio}

+

${authors.find(function (author) { return author.author === item.author} ).bio}

${item.article}

@@ -24,7 +24,7 @@ async function getArticlesAndAuthors() { app.innerHTML = 'Fetching all articles and authors...'; try { - let responses = await Promise.all([fetch(endpoints.articles), fetch(endpoints.authors)]); + let responses = await Promise.all(endpoints.map( function (endpoint) { return fetch(endpoint); } )); let articlesAndAuthors = await Promise.all(responses.map(async function (response) { if (!response.ok) throw response.status;