shfshanyue / Daily-Question

互联网大厂内推及大厂面经整理,并且每天一道面试题推送。每天五分钟,半年大厂中
https://q.shanyue.tech
4.95k stars 509 forks source link

代码 #790

Closed yuyuyu-alan closed 2 years ago

yuyuyu-alan commented 2 years ago

const getFrequentChar = (str) => { let maps = new Map(); for(let i of str) { maps.set(i, maps.has(i) ? maps.get(i) + 1 : 0) } return [...maps].reduce((a, b) => a[1] > b[1] ? [a[0], a[1]] : [b[0], b[1]], []) }