Fe-interview: [js] 第453天 给你一个页面,找出该页面使用最多的前三个标签以及他们的数量

Created on 11 Jul 2020  ·  1Comment  ·  Source: haizlin/fe-interview

第453天 给你一个页面,找出该页面使用最多的前三个标签以及他们的数量

作者:cxwht

3+1官网

我也要出题

js

Most helpful comment

    const tagSet = Array.from(document.querySelectorAll('*'))
    .map(item => item.tagName)
    .reduce((res, item) => {
        if (res[item]) {
            res[item] = res[item] + 1;
        } else {
            res[item] = 1;
        }
        return res;
    }, {});


 const res = Object.keys(tagSet).map(item => ({
        key: item,
        value: tagSet[item]
    })).sort((a, b) => b.value - a.value)
   

console.log(res);


>All comments

    const tagSet = Array.from(document.querySelectorAll('*'))
    .map(item => item.tagName)
    .reduce((res, item) => {
        if (res[item]) {
            res[item] = res[item] + 1;
        } else {
            res[item] = 1;
        }
        return res;
    }, {});


 const res = Object.keys(tagSet).map(item => ({
        key: item,
        value: tagSet[item]
    })).sort((a, b) => b.value - a.value)
   

console.log(res);


Was this page helpful?
0 / 5 - 0 ratings