Update sort return

This commit is contained in:
Em (Ethan) Ruszanowski 2024-09-10 13:10:55 -04:00
parent fecb114063
commit 6ade503338
Signed by: em
GPG key ID: C725D6E571252B96

View file

@ -10,7 +10,7 @@ async function sortHackerNewsArticles() {
// go to Hacker News // go to Hacker News
await page.goto("https://news.ycombinator.com/newest"); await page.goto("https://news.ycombinator.com/newest");
// instantiate array for all date objects // instantiate empty array for all date objects
let datestamps = []; let datestamps = [];
// loop through process per page // loop through process per page
@ -31,18 +31,14 @@ async function sortHackerNewsArticles() {
// drop extra array elements // drop extra array elements
datestamps.splice(100, 20); datestamps.splice(100, 20);
// check if the website dates are sorted and report results // check if the website dates are sorted and return results
if (datestamps === datestamps.sort()) { return 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.",
);
}
} }
(async () => { (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.");
}
})(); })();