Skip to content

Instantly share code, notes, and snippets.

@caffeinum
Last active June 10, 2022 20:54
Show Gist options
  • Save caffeinum/a549f1e0d991f3ebfd3c3f710a31196a to your computer and use it in GitHub Desktop.
Save caffeinum/a549f1e0d991f3ebfd3c3f710a31196a to your computer and use it in GitHub Desktop.
@caffeinum
Copy link
Author

caffeinum commented Oct 7, 2021

Sorting names, filtering filetypes

const files = arr.slice(1).reduce((acc, elem) => [ ...acc, elem ? { href: elem.children.item(2).children.item(0).href, name: elem.children.item(1).innerText } : {} ], [])

const images = files.filter(i => i.name).filter(i => i.name.includes('jpg'))

const imagesOrdered = images.map(i => ({ ...i, order: parseInt(i.name.replace(/[^\d]+/g, "")) }).sort((a,b) => a.order - b.order)

const links = imagesOrdered.map(i => i.href)

JSON.stringify(links)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment