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

16 lines
321 B
JavaScript
Raw Normal View History

export function mostUsedChar(text) {
2022-11-02 17:50:03 +00:00
var getMax = function (str) {
var max = 0,
maxChar = "";
str.split("").forEach(function (char) {
if (str.split(char).length > max) {
max = str.split(char).length;
maxChar = char;
}
});
return maxChar;
};
2022-11-02 14:59:41 +00:00
2022-11-02 17:50:03 +00:00
return getMax(text);
}