forked from M3-Academy/challenge-algorithms-v2.0
16 lines
279 B
JavaScript
16 lines
279 B
JavaScript
export function mostUsedChar(text) {
|
|
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;
|
|
}
|