1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| var str = 'cbdefdfpoweqwlkjsaaaaz' function findMostLetter(str) { let match = str .replace(" ", "") .split("") .sort() .join("") .match(/(\w)\1*/g); let res = ""; let len = 0; match.forEach((val, key) => { if (val.length > len) { res = val[0]; len = val.length; } }); return res; }
findMostLetter(str)
|