Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
using split and length to find frequency solution in Creative category for The Most Wanted Letter by lolucky
import assert from "assert";
function mostWanted(t: string): string {
t=t.toLowerCase();
let rep=a=>t.split(a).length;
return t.split("").sort().filter(v=>/[a-z]/g.test(v)).sort((a,b)=>rep(b)-rep(a))[0];
}
console.log('Example:');
console.log(mostWanted('AAaooo'));
// 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!");
July 3, 2020
Comments: