Fix array splice

This commit is contained in:
Em (Ethan) Ruszanowski 2024-09-10 00:25:05 -04:00
parent 1b70ac612e
commit fecb114063
Signed by: em
GPG key ID: C725D6E571252B96
2 changed files with 14 additions and 10 deletions

View file

@ -6,7 +6,7 @@ Welcome to the QA Wolf take home assignment for our [QA Engineer](https://www.no
This assignment has two questions as outlined below. When you are done, send [qa-hiring@qawolf.com](mailto:qa-hiring@qawolf.com) the following:
1. A link to a zip file of this folder on Google Drive
1. A link to a zip file of this folder on Google Drive
2. A note indicating your work location (Country/State)

View file

@ -11,31 +11,35 @@ async function sortHackerNewsArticles() {
await page.goto("https://news.ycombinator.com/newest");
// instantiate array for all date objects
let datestamps = []
let datestamps = [];
// loop through process per page
for (var pageview = 0; pageview <= 3; pageview++) {
// locate each article's age span
let datespans = await page.locator('.age').all();
let datespans = await page.locator(".age").all();
// iterate through date spans to get timestamps
for (row = 0; row < datespans.length; row++) {
// turn timestamp strings into date objects and push to array
datestamps.push(new Date(await datespans[row].getAttribute('title')));
datestamps.push(new Date(await datespans[row].getAttribute("title")));
}
// click the next button as needed
await page.getByRole('link', { name: 'More', exact: true }).click();
await page.getByRole("link", { name: "More", exact: true }).click();
}
// drop extra articles from last page grab
datestamps = datestamps.slice(0, 100);
// drop extra array elements
datestamps.splice(100, 20);
// report results
// 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.")
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.")
console.log(
"Failure… The first 100 articles are not correctly sorted by posting time.",
);
}
}