79636440

Date: 2025-05-24 04:44:10
Score: 2.5
Natty:
Report link

This one is working as well but when I have more than one key with the same value, It just shows only one. The text that I have tried is has two character with the same value like this: (E:6:S:6) I want to show a result for each of them. Like: The character E has repeated 6 times in the string The character S has repeated 6 times in the string I just have The character E has repeated 6 times in the string. I have tried to make it work, but not yet, it seems like i need to do some special trick, so if you have some int, on how i can do that feel free to provide it to me please.

const frequentChar = str =>{
    const {max, ...counts} = str.toLowerCase().replace(/\s/g, "").split("").reduce((start, val) =>{
        start[val] = start[val] ? start[val]+1 : 1;
        start.max = start.max < start[val]? start[val] : start.max;
        return start;
    }, {max: 0});

    const result = [...Object.entries(counts).filter(([key, val]) => val === max)]
    const finalResult = result.join(",").replace(/,/g, ":").toUpperCase()
    console.log(finalResult);
    return `The character ${finalResult[0]} has repeated ${finalResult[2]} times in the string`
}

console.log(frequentChar(text))
Reasons:
  • Blacklisted phrase (0.5): i need
  • RegEx Blacklisted phrase (1): I want
  • RegEx Blacklisted phrase (1): i can do that feel free to provide it to me please
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: DAVE LOVE