Skip to content

Instantly share code, notes, and snippets.

@seunzone
Last active March 29, 2019 12:00
Show Gist options
  • Save seunzone/ca27dc13921316d6584ee9968b004cfb to your computer and use it in GitHub Desktop.
Save seunzone/ca27dc13921316d6584ee9968b004cfb to your computer and use it in GitHub Desktop.
const maxChar = str => {
const myStr = str.toLowerCase();
const charMap = {};
let max = 0;
let maxChar = '';
for (let char of myStr) {
if (!charMap[char]) {
charMap[char] = 1;
} else {
charMap[char]++;
}
}
for (let char in charMap) {
if (charMap[char] > max) {
max = charMap[char];
maxChar = char;
}
}
return maxChar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment