getElementsByClassName() is a method that exists on HTML Documents and Elements to return an HTMLCollection of descendant elements within the Document/Element that have the specified class name(s).
Implement a custom Element.getElementsByClassName() that is similar but slightly different:
classNames string containing one or more class names to match, separated by whitespace. For example, getElementsByClassName(document.body, 'foo bar').Element.getElementsByClassName(), only descendants of the element argument are searched, not the element itself.Elements instead of an HTMLCollection of Elements.Do not use document.querySelectorAll(), which would make the problem trivial. You will not be allowed to use it during real interviews.
const doc = new DOMParser().parseFromString(`<div class="foo bar baz"><span class="bar baz">Span</span><p class="foo baz">Paragraph</p><div class="foo bar"></div></div>`,'text/html',);getElementsByClassName(doc.body, 'foo bar');// [div.foo.bar.baz, div.foo.bar] <-- This is an array of elements.
console.log() statements will appear here.