From fecb1140631c3baeec95f772c0216f0ca92aa8fc Mon Sep 17 00:00:00 2001 From: Ethan Ruszanowski Date: Tue, 10 Sep 2024 00:25:05 -0400 Subject: [PATCH] Fix array splice --- README.md | 2 +- index.js | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9f44c7e..a912935 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/index.js b/index.js index ab566bd..6a0019e 100644 --- a/index.js +++ b/index.js @@ -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.", + ); } }