题解 | #简单错误记录#

简单错误记录

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

const rl = require("readline").createInterface({ input: process.stdin })

class Developer {
  constructor() {
    this.list = []
    this.cache = {}
  }

  get listLen () {
    return this.list.length
  }

  input (line) {
    const [path, num] = line.split(' ')
    if (!path) return
    const fileName = this.getFileName(path)
    const key = `${fileName}${num}`
    if (this.cache[key]) {
      this.cache[key].count ++
    } else {
      const obj = Object.create(null)
      obj.fileName = fileName
      obj.num = num
      obj.count = 1

      this.cache[key] = obj

      this.list.push(obj)
    }
  }

  output () {
    if (!this.listLen) return
    let len = 8
    while (len > 0) {
      if (len > this.listLen) {
        len = this.listLen
      }
      const obj = this.list[this.listLen - len]
      console.log(`${obj.fileName} ${obj.num} ${obj.count}`)
      len --
    }
  }

  getFileName (path, bit = 16) {
    const items = path.split('\\')
    const name = items[items.length - 1]
    return name.length <= bit ? name : name.slice(0 - bit)
  }
}

const developer = new Developer()
rl.on('line', (line) => {
  if (line === 'end') {
    rl.close()
    return
  }
  developer.input(line)
})

rl.on('close', () => {
  developer.output()
})

全部评论

相关推荐

02-14 12:40
门头沟学院 Java
程序员花海:1.面试要求必须Java笔试不一定 2.难度对等秋招 远超于日常实习是因为同一批次且转正很多 竞争压力大 3.第一个加点指标,上线了就把接口性能加上去 使用本地缓存这个不算亮点 只是技术选型,要把为什么采用这个和背后的思考写出来而不是单纯堆叠技术没意义 4.八股要一直看 很容易忘记 5.拼团交易这个老问题 堆积技术 另外建议你把奖项合并到教育背景 没必要拆出来放最后
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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