challenge-algorithms-v2.0-h.../09-mostRepeatedChar/index.js

16 lines
279 B
JavaScript
Raw Permalink Normal View History

export function mostUsedChar(text) {
2022-10-28 00:35:13 +00:00
if (!text) return { error: 'Not Found Text' };
let max = 0,
maxChar = '';
for (let char of text) {
if (text.split(char).length > max) {
max = text.split(char).length;
maxChar = char;
}
}
return maxChar;
}