Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Most Wanted Letter by mortonfox
import assert from "assert";
function mostWanted(text: string): string {
let freqs = [...text.toLowerCase().replace(/[^a-z]/g, '')].reduce(
(res, c) => (res[c] = (res[c] || 0) + 1, res), {}
);
return Object.keys(freqs).sort(
(a, b) => freqs[a] === freqs[b] ? a.localeCompare(b) : freqs[b] - freqs[a]
)[0];
}
console.log('Example:');
console.log(mostWanted('Hello World!'));
// These "asserts" are used for self-checking
assert.equal(mostWanted('Hello World!'), 'l');
assert.equal(mostWanted('How do you do?'), 'o');
assert.equal(mostWanted('One'), 'e');
assert.equal(mostWanted('Oops!'), 'o');
assert.equal(mostWanted('AAaooo!!!!'), 'a');
assert.equal(mostWanted('abe'), 'a');
console.log("Coding complete? Click 'Check' to earn cool rewards!");
May 19, 2020
Comments: