javascript max characters string function
const getMaxLetter = (str) => {
let max = 0;
let maxChar = '';
str.split('').forEach((char) => {
if (str.split(char).length > max) {
max = str.split(char).length - 1;
maxChar = char;
}
});
return `The max letter is : ${maxChar} and the max number of times it is seen is: ${max} times`;
};function maxChar(str) {
let charCountObj = {};
let maxChar = "";
let maxCount = 0;
// Fill out CharCountObj
// Updates new MaxCount
for (let i = 0; i < str.length; i++) {
const char = str[i];
charCountObj[char] = charCountObj[char] + 1 || 1;
if (charCountObj[char] > maxCount) {
maxChar = char;
maxCount = charCountObj[char];
}
}
return maxChar;
}
Also in JavaScript:
- javascript stringify an object
- jquery infinite scroll
- Your global Angular CLI version (11.0.2) is greater than your local version
- javascript innertext vs innerhtml
- json server
- document ready js
- run javascript when typing
- how to run different node app on server different domains
- javascript date get day of week abbreviation
- node start is too slow windows 10
- not equal to sign in js
- javascript project ideas
- cJSON_CreateObject
- convert timestamp to date js
- getpermutation js recursion
- hoe verbind je de nodemcu 8266 met adafruit io
- js conditional key
- sum in javascript
- display json data in html table using javascript dynamically
- react native init project
- check if date is today js
- ant design react
- get syntethicbaseevent and parameter in react
- hello world in javascript