type listType = [string, number][]type keyByFunction = (tag: [string, number]) => numberconst maxBy = (list: listType, keyBy:keyByFunction) => { return list.reduce((x, y) => { return keyBy(x) > keyBy(y) ? x : y })}const filterTag:keyByFunction = tag => tag[1]const getMostFrequent = () => { const tags = [...document.querySelectorAll('*')] .map(tag => tag.tagName) .reduce((acc, cur) => { acc[cur] = acc[cur] ? acc[cur] + 1 : 1 return acc }, {}) return maxBy(Object.entries(tags), filterTag)}// Todo: querySelectorAll polyfilltype elType = HTMLElement | Document | Elementconst getAllTags = (el: elType = document) => { const children = Array.from(el.children) .reduce((acc, cur) => [...acc, ...getAllTags(cur)], []) return children}