题解 | #简单错误记录#

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let errorDoumentURLArr = [];
rl.on("line", function (line) {
    if (!errorDoumentURLArr.includes(line)) {
        errorDoumentURLArr.push(line);
    }
});

rl.on("close", () => {
    const helperQueue = [];
    const helperMap = new Map();
    const length = errorDoumentURLArr.length;
    for (let i = 0; i < length; i++) {
        const [errorDocumentURI, lineNum] = errorDoumentURLArr[i].split(" ");
        let errorDocument = errorDocumentURI.split("\\").pop();
        if (errorDocument.length > 16) {
            const startIndex = errorDocument.length - 16;
            errorDocument = errorDocument.slice(startIndex);
        }
        const relErrorDocument = errorDocument + " " + lineNum;
        helperMap.set(
            relErrorDocument,
            (helperMap.get(relErrorDocument) || 0) + 1
        );
		// helperMap.get(relErrorDocument) < 2 表示如果队列里没有这个文件 但前面这个文件已经出现过了 就和前一个文件合并一起丢弃就不用计算在内了
        if (!helperQueue.includes(relErrorDocument) && helperMap.get(relErrorDocument) < 2) {
            helperQueue.push(relErrorDocument);
            if (helperQueue.length > 8) {
                helperQueue.shift();
            }
        }
    }
    for (const relErrorDocument of helperQueue) {
        console.log(relErrorDocument, helperMap.get(relErrorDocument));
    }
});

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-11 13:34
门头沟学院 C++
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
大佬们,在大厂实习的都是几百一天???
爱睡觉的冰箱哥:实习工资这个不都是公开的吗,a不了,字节400,快手350,有些有房补餐补这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务