how to print the most continuously repeated character in a
string?



how to print the most continuously repeated character in a string?..

Answer / Sanjit Choudhary

To find and print the most frequently occurring character in a string using JavaScript, you can use the following code: `let str = 'your string'; let charFreq = {}; for (let i=0; i<str.length; i++){ if(charFreq[str[i]]){ charFreq[str[i]]++;} else { charFreq[str[i]] = 1;} } let maxChar = ''; let maxCount = 0; for (const [key, value] of Object.entries(charFreq)) { if(value > maxCount){ maxCount = value; maxChar = key;}} console.log(maxChar);`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Everything Else AllOther Interview Questions

hey I m working in retail bankIng as teller yet another 1yr I m going to work for dis bank....after quitting from dis werelse I can get job apart from banking sector

1 Answers  


Which of the following is not determined by RBI?

1 Answers  


Why our fingers are not in equal length?

1 Answers   Shore Infotech,


what do you know about this company ?

0 Answers  


How to install the kernel patches in solaris

0 Answers  


Hello All, I am a student of CSE from JNTU...still i have backlogs...i dont have chances to write again....till now i worked as US Recruiter & Technical support in small companies...is there any company which is considering talent as measurement not with certificates. to get a job...Please let me know

1 Answers  


How can you do value addition to this company?

0 Answers   ICICI,


what is the diffreence between sales insurance and other marketing ?

1 Answers   Max Newyork Life Insurance,


we are a well established company but what weakness do you feel in our product?

1 Answers  


sell me this stapler......(this pencil...this clock... or other object on interviewer's desk).

1 Answers   Home Credit,


Notice period ?

0 Answers  


WHY YOU ARE APPLING OR INTERESTED FOR THE POSITION BRANCH MANAGER?

0 Answers  


Categories