Instead of looking through all the links, checking if we have any with HREFs that contain "drop_box", and then looking through them all again, you could just switch this all to a single Array.filter(), and then a forEach on the items provided by the filter. Cheerio has an equivalent filter function. Since forEach doesn't run on an empty arrays (or throw an error), you would be able to skip a lot of the checking happening here.
https://github.com/byuitechops/action-series-master/blob/6242a2ffc0f996c03860c1fecf92d3674e47ac5e/actions/universal-fix-dropbox-links.js#L161-L190
Instead of looking through all the links, checking if we have any with HREFs that contain "drop_box", and then looking through them all again, you could just switch this all to a single
Array.filter()
, and then aforEach
on the items provided by the filter. Cheerio has an equivalentfilter
function. SinceforEach
doesn't run on an empty arrays (or throw an error), you would be able to skip a lot of the checking happening here.