Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function maxChar(str) {
  2. let count = {};
  3. let max = 0;
  4. let maxChar = "";
  5.  
  6. for (let char of str) {
  7. // count[char] = count[char] ? count[char] + 1 : 1;
  8. count[char] = count[char] + 1 || 1;
  9. }
  10.  
  11. for (let n in count) {
  12. if (max < count[n]) {
  13. max = count[n];
  14. maxChar = n;
  15. }
  16. }
  17. return maxChar;
  18. }
  19.  
  20. console.log(maxChar("Hello there!"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement