functional programming

This commit is contained in:
Zynh0722 2024-04-02 19:33:13 -07:00
parent 4b9311c61f
commit f9a5d5cdac

View file

@ -14,8 +14,10 @@ async function getPatchHrefs() {
let patchHrefs: string[] = []; let patchHrefs: string[] = [];
for (let i = 0; i <= 7; i++) { [...Array(7).keys()]
const req = await fetch(getGalleryPageHref(i)); .map((val) => ++val)
.map(async (page) => {
const req = await fetch(getGalleryPageHref(page));
const data = parse(await req.text()); const data = parse(await req.text());
const gallery = data const gallery = data
@ -23,15 +25,11 @@ async function getPatchHrefs() {
.filter((el) => el.classList.contains("hds-gallery-items")) .filter((el) => el.classList.contains("hds-gallery-items"))
.shift(); .shift();
const links = gallery return gallery
?.getElementsByTagName("a") ?.getElementsByTagName("a")
.map((el) => el.getAttribute("href")) .map((el) => el.getAttribute("href"))
.filter((el) => el) as string[]; .filter((el) => el) as string[];
});
patchHrefs.push.apply(patchHrefs, links);
}
return patchHrefs;
} }
const allPatches = await getPatchHrefs(); const allPatches = await getPatchHrefs();