Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const maxStringCounter = str => {
- let obj = {};
- str.split("").forEach(el => {
- if (obj[el]) {
- return (obj[el] += 1);
- } else {
- return (obj[el] = 1);
- }
- });
- const values = Object.values(obj);
- const keys = Object.keys(obj); //?
- const maxValue = Math.max(...values);
- const indexOfLargestValue = values.indexOf(maxValue);
- return keys[indexOfLargestValue];
- };
- maxStringCounter("44123"); // 4
- maxStringCounter("441111123"); // 1
Add Comment
Please, Sign In to add comment