Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created September 17, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/e4a5f7e1d7c160d2a5d856ab66bfd657 to your computer and use it in GitHub Desktop.
Save crutchcorn/e4a5f7e1d7c160d2a5d856ab66bfd657 to your computer and use it in GitHub Desktop.
recursive = (el) => el.children && el.children.length !== 0 ? Array.from(el.children).reduce((prev, child) => [...prev, ...recursive(child)], Array.from(el.children)) : [el];
$$('.js-hotel-result').forEach(hotelEl => {
const isBad = recursive(hotelEl).reduce((prev, el) => prev || !!(/^ ?[2-9][0-9](?:\.[0-9]+)? miles.*/).exec(el.innerText), false);
if (isBad) {
hotelEl.parentNode.removeChild(hotelEl);
}
});
@crutchcorn
Copy link
Author

A more readible version of this would be:

function recursive(el) {
	if (el.children && el.children.length !== 0) {
		
		const elChildren = Array.from(el.children);
		let allElements = [...elChildren];

		for (let child of elChildren) {
			const childChildren = recursive(child);
			allElements = allElements.concat(childChildren)
		}

		return allElements;
	} else {
		return [el];
 	}
}

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