Sometimes UI behavior is controlled by hiding a container instead of hiding each descendant individually. If several elements need to disappear together, it is useful to know the deepest element in the DOM tree that contains all of them.
Implement lowestHidingElement(elements), which takes a non-empty array of DOM elements and returns the deepest element that would hide all of them if that element were hidden.
const page = new DOMParser().parseFromString(`<main><section><button>Save</button><button>Cancel</button></section><aside><button>Archive</button></aside></main>`,'text/html',);const section = page.body.firstElementChild.firstElementChild;const saveButton = section.firstElementChild;const cancelButton = section.lastElementChild;lowestHidingElement([saveButton, cancelButton]);// section
const page = new DOMParser().parseFromString(`<main><nav><ul><li><a href="/docs">Docs</a></li><li><a href="/api">API</a></li></ul></nav></main>`,'text/html',);const list = page.body.firstElementChild.firstElementChild.firstElementChild;const firstLink = list.firstElementChild.firstElementChild;lowestHidingElement([list, firstLink]);// list
lowestHidingElement(elements)
elements (Element[]): A non-empty array of elements from the same document tree.Returns the deepest Element that contains every element in elements.
console.log() aparecerão aqui.