From f9a5d5cdac6db302e7325086b9f0149d1919daf4 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Tue, 2 Apr 2024 19:33:13 -0700 Subject: [PATCH] functional programming --- index.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/index.ts b/index.ts index f8db88b..75aa94f 100644 --- a/index.ts +++ b/index.ts @@ -14,24 +14,22 @@ async function getPatchHrefs() { let patchHrefs: string[] = []; - for (let i = 0; i <= 7; i++) { - const req = await fetch(getGalleryPageHref(i)); - const data = parse(await req.text()); + [...Array(7).keys()] + .map((val) => ++val) + .map(async (page) => { + const req = await fetch(getGalleryPageHref(page)); + const data = parse(await req.text()); - const gallery = data - .getElementsByTagName("div") - .filter((el) => el.classList.contains("hds-gallery-items")) - .shift(); + const gallery = data + .getElementsByTagName("div") + .filter((el) => el.classList.contains("hds-gallery-items")) + .shift(); - const links = gallery - ?.getElementsByTagName("a") - .map((el) => el.getAttribute("href")) - .filter((el) => el) as string[]; - - patchHrefs.push.apply(patchHrefs, links); - } - - return patchHrefs; + return gallery + ?.getElementsByTagName("a") + .map((el) => el.getAttribute("href")) + .filter((el) => el) as string[]; + }); } const allPatches = await getPatchHrefs();