Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Survey Junkie is the #1 place online for your audience to earn rewards for their opinion.

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
Liquid Web - Highest Level of Performance and Security with Managed Dedicated Servers

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

21,340 questions

28,142 answers

573 users

How to find highest frequency character in a string with TypeScript

1 Answer

0 votes
function get_highest_frequency_character(s: string) : string { 
    const TOTLAASCII = 256; 
    let arr = new Array(TOTLAASCII).fill(0);
    const len = s.length; 
    for (let i = 0; i < len; i++) {
    let max = arr[0]; 
    let ch = ' '; 
    for (let i = 1; i < len; i++) { 
        if (max < arr[s[i].charCodeAt(0)]) { 
            max = arr[s[i].charCodeAt(0)]; 
            ch = s[i]; 
    return ch; 
const s = "typescriptc++phpcpythonc#"; 
console.log("Highest frequency character: " + get_highest_frequency_character(s)); 
"Highest frequency character: p" 


answered Jan 13 by avibootz