Update sort return
This commit is contained in:
parent
fecb114063
commit
6ade503338
1 changed files with 8 additions and 12 deletions
20
index.js
20
index.js
|
@ -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.");
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue