题解 | #简单错误记录#

简单错误记录

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    let list=[]
    while(line = await readline()){
        let ordin=line.split('\\').at(-1).split(' ').pop();
        let name=line.split('\\').at(-1).split(' ')[0].slice(-16);
        let num=1;
        let index=list.findIndex(item=>item.name==name&&item.ordin==ordin)
        if(index!=-1){
            list[index].num++
        }else{
            list.push({name,ordin,num});
        }
    }
    list.slice(-8).forEach(item=>{
        console.log(item.name+' '+item.ordin+' '+item.num)
    })
}()

这道题,让我了解数组的findindex用法,以及如何将一个动态的对象push进数组中

全部评论

相关推荐

01-02 21:17
已编辑
西安理工大学 后端
程序员小白条:项目不太重要,你的优势的算法竞赛,然后多背相关的八股文,项目可以不作为重点考虑,面试可能就简单带过项目就行了,你可以直接写简历,背项目相关的八股文就行,也不用自己做,时间紧张的情况下,性价比最高
点赞 评论 收藏
分享
01-21 12:26
暨南大学 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务