1. type listType = [string, number][]
    2. type keyByFunction = (tag: [string, number]) => number
    3. const maxBy = (list: listType, keyBy:keyByFunction) => {
    4. return list.reduce((x, y) => {
    5. return keyBy(x) > keyBy(y) ? x : y
    6. })
    7. }
    8. const filterTag:keyByFunction = tag => tag[1]
    9. const getMostFrequent = () => {
    10. const tags = [...document.querySelectorAll('*')]
    11. .map(tag => tag.tagName)
    12. .reduce((acc, cur) => {
    13. acc[cur] = acc[cur] ? acc[cur] + 1 : 1
    14. return acc
    15. }, {})
    16. return maxBy(Object.entries(tags), filterTag)
    17. }
    18. // Todo: querySelectorAll polyfill
    19. type elType = HTMLElement | Document | Element
    20. const getAllTags = (el: elType = document) => {
    21. const children = Array.from(el.children)
    22. .reduce((acc, cur) => [...acc, ...getAllTags(cur)], [])
    23. return children
    24. }