Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function maxChar(str) {
- let count = {};
- let max = 0;
- let maxChar = "";
- for (let char of str) {
- // count[char] = count[char] ? count[char] + 1 : 1;
- count[char] = count[char] + 1 || 1;
- }
- for (let n in count) {
- if (max < count[n]) {
- max = count[n];
- maxChar = n;
- }
- }
- return maxChar;
- }
- console.log(maxChar("Hello there!"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement