From 6ade503338030f4fd247c28af6e1493ff80db2bf Mon Sep 17 00:00:00 2001 From: Ethan Ruszanowski Date: Tue, 10 Sep 2024 13:10:55 -0400 Subject: [PATCH] Update sort return --- index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 6a0019e..b80b198 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ async function sortHackerNewsArticles() { // go to Hacker News await page.goto("https://news.ycombinator.com/newest"); - // instantiate array for all date objects + // instantiate empty array for all date objects let datestamps = []; // loop through process per page @@ -31,18 +31,14 @@ async function sortHackerNewsArticles() { // drop extra array elements datestamps.splice(100, 20); - // check if the website dates are sorted and report results - if (datestamps === datestamps.sort()) { - console.log( - "Success! The first 100 articles are correctly sorted by posting time.", - ); - } else { - console.log( - "Failureā€¦ The first 100 articles are not correctly sorted by posting time.", - ); - } + // check if the website dates are sorted and return results + return datestamps === datestamps.sort(); } (async () => { - await sortHackerNewsArticles(); + if (await sortHackerNewsArticles()) { + console.log("Success! The first 100 articles were sorted correctly."); + } else { + console.log("Failureā€¦ The first 100 articles were not sorted correctly."); + } })();